Question : There is data on jump host that needs to be copied on all application servers in Stratos DC. Nautilus DevOps team want to perform this task using Ansible only. Perform this task using Ansible as per details mentioned below:
a. On jump host create an inventory file /home/thor/ansible/inventory and add all application servers as managed nodes.
b. On jump host create a playbook /home/thor/ansible/playbook.yml to copy /usr/src/sysops/index.html file to all application servers at location /opt/sysops.
Note: Validation will try to run playbook using command ansible-playbook -i inventory playbook.yml so please make sure playbook works this way, without passing 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/sysops" -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 sysops folder copy: src=/usr/src/sysops/index.html
dest=/opt/sysops 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 sysops 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/sysops" -i inventory stapp02 |
CHANGED | rc=0 >> total 4 -rw-r--r-- 1
root root 35 Jul 29 09:56 index.html stapp03 |
CHANGED | rc=0 >> total 4 -rw-r--r-- 1
root root 35 Jul 29 09:56 index.html stapp01 |
CHANGED | rc=0 >> total 4 -rw-r--r-- 1
root root 35 Jul 29 09:56 index.html thor@jump_host
~/ansible$ |
Happy Learning!!!!
0 Comments