Ansible with AWS and EC2

The translation of the article was prepared on the eve of the start of the course "Infrastructure platform based on Kubernetes" .


I suggest you roll up your sleeves and dive into Ansible tasks using AWS EC2. We'll walk through how to install and uninstall a package using Ansible.

RnD VizuaMatix c ansible. Ansible - - , YouTube ansible . , Ansible. Ansible AWS EC2.

(master node, β€œβ€) (worker node, β€œβ€) . Ubuntu 18.04.4. . VLC , .


Ansible (-). :

sudo apt install ansible

. ssh- .

ssh-keygen -t rsa -N β€œβ€ -f /home/ubuntu/.ssh/idrsa

cat cat .ssh/idrsa.pub

vim ~/.ssh/authorized_keys , . .

, :

ssh -i ~/.ssh/id_rsa username@instance_ip

, .

ansible.   /etc/ansible/hosts . [workers]. , workers playbook, ansible , playbook.

[workers]

[workers]
node_ip_address

, : ansible workers -m ping

, SUCCESS pong

| SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

- , . AWS-EC2 Ansible. VLC.


Playbook

Ansible playbook. yaml . playbooks ansible.

playbook vlc: installvlc.yaml

---
  - name: installvlc      #  playbook
    hosts: workers        #   
    become: true          #   sudo user
   tasks:
      - name: Install VLC Media Player
        apt:                            #  
          name: vlc-bin
          state: latest                
#     ,      state: 3.0.0

playbook ,

ansible-playbook installvlc.yaml

, - :

PLAY [installvlc] *********************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************
ok: []
TASK [Install VLC Media Player] *******************************************************************************************************
changed: []
PLAY RECAP ****************************************************************************************************************************
 : ok=2    changed=1    unreachable=0    failed=0

changed=1 , playbook . playbook, changed=0. , (state) .

: vlc , - VLC media player 3.0.8 Vetinari (revision 3.0.8–0-gf350b6b5a7).

Playbook

, , , :

state: absent

playbook , state . , . playbook ansible-playbook uninstallvlc.yaml

Ansible - . , yaml playbook. , ansible , IoT .

, ansible. , , . .


Demo- : " Kubernetes"





All Articles