Question : The Nautilus DevOps team needs to copy data from the jump host to all application servers in Stratos DC using Ansible. Execute the task with the following details:
a. Create an inventory file /home/thor/ansible/inventory on jump_host and add all application servers as managed nodes.
b. Create a playbook /home/thor/ansible/playbook.yml on the jump host to copy the /usr/src/security/index.html file to all application servers, placing it at /opt/security.
Note: Validation will run the playbook using the command ansible-playbook -i inventory playbook.yml. Ensure the playbook functions properly without any extra arguments.
1. Go through the folder mentioned in the task and create inventory & playbook files
thor@jump_host /$ cd /home/thor/ansible/ thor@jump_host ~/ansible$ ll total 0 thor@jump_host ~/ansible$ |
2. Create an inventory file and add the app servers as per task.
thor@jump_host ~/ansible$ vi inventory thor@jump_host ~/ansible$ cat inventory stapp01 ansible_host=172.16.238.10 ansible_ssh_pass=Ir0nM@n ansible_user=tony stapp02 ansible_host=172.16.238.11 ansible_ssh_pass=Am3ric@ ansible_user=steve stapp03 ansible_host=172.16.238.12 ansible_ssh_pass=BigGr33n ansible_user=banner thor@jump_host ~/ansible$ |
thor@jump_host ~/ansible$ ansible all -a "ls -ltr /opt/security" -i inventory stapp02 | CHANGED | rc=0 >> total 0 stapp03 | CHANGED | rc=0 >> total 0 stapp01 | CHANGED | rc=0 >> total 0 thor@jump_host ~/ansible$ |
thor@jump_host ~/ansible$ vi playbook.yml thor@jump_host ~/ansible$ cat playbook.yml - name: Ansible copy hosts: all become: yes tasks: - name: copy index.html to security folder copy: src=/usr/src/security/index.html dest=/opt/security thor@jump_host ~/ansible$ |
5.Post file saved, run below command to execute the playbook
thor@jump_host ~/ansible$ ansible-playbook -i inventory playbook.yml
PLAY [ansible copy] *********************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************** ok: [stapp03] ok: [stapp01] ok: [stapp02]
TASK [copy index.html to security folder] ************************************************************************************* changed: [stapp03] changed: [stapp01] changed: [stapp02]
PLAY RECAP ****************************************************************************************************************** stapp01 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 stapp02 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 stapp03 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
thor@jump_host ~/ansible$ |
thor@jump_host ~/ansible$ ansible all -a "ls -ltr /opt/security" -i inventory stapp01 | CHANGED | rc=0 >> total 4 -rw-r--r-- 1 root root 35 Jul 10 07:45 index.html stapp02 | CHANGED | rc=0 >> total 4 -rw-r--r-- 1 root root 35 Jul 10 07:45 index.html stapp03 | CHANGED | rc=0 >> total 4 -rw-r--r-- 1 root root 35 Jul 10 07:45 index.html thor@jump_host ~/ansible$ |
Happy Learning!!!!
0 Comments