Question : The Nautilus DevOps team has some data on jump host in Stratos DC that they want to copy on all app servers in the same data center. However, they want to create an archive of data and copy it to the app servers. Additionally, there are some specific requirements for each server. Perform the task using Ansible playbook as per requirements mentioned below:
Create a playbook.yml under /home/thor/ansible on jump host, an inventory file is already placed under /home/thor/ansible/ on Jump Server itself.
1. At first ansible inventory file is working properly and doesn't have any file exist from jump server to all the app server's
thor@jump_host
/$ cd /home/thor/ansible/ thor@jump_host
~/ansible$ ansible all -a "ls -ltr /opt/sysops" -i inventory stapp01 |
CHANGED | rc=0 >> total 0 stapp03 |
CHANGED | rc=0 >> total 0 stapp02 |
CHANGED | rc=0 >> total 0 thor@jump_host
~/ansible$ |
2. If you see above output then create playbook file ( refer video for more details )
thor@jump_host
~/ansible$ vi /home/thor/ansible/playbook.yml thor@jump_host
~/ansible$ cat /home/thor/ansible/playbook.yml - name: Task
create archive and copy to host hosts: stapp01, stapp02, stapp03 become: yes tasks: - name: As per the task create the
archive file and set the owner archive: path: /usr/src/sysops/ dest: /opt/sysops/beta.tar.gz format: gz force_archive: true owner: "{{ ansible_user }}" group: "{{ ansible_user }}" thor@jump_host ~/ansible$ |
thor@jump_host
~/ansible$ ansible-playbook -i
inventory playbook.yml PLAY [Task create archive and copy to host] *************************************************************** TASK [Gathering Facts] ************************************************************************************ ok: [stapp01] ok: [stapp02] ok: [stapp03] TASK [As per the task create the archive file and set the owner] ****************************************** 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 stapp03 |
CHANGED | rc=0 >> total 4 -rw-r--r-- 1
banner banner 164 Jun 14 05:19 beta.tar.gz stapp02 |
CHANGED | rc=0 >> total 4 -rw-r--r-- 1
steve steve 176 Jun 14 05:19 beta.tar.gz stapp01 |
CHANGED | rc=0 >> total 4 -rw-r--r-- 1
tony tony 167 Jun 14 05:19 beta.tar.gz thor@jump_host
~/ansible$ |
Happy Learning!!!!
3 Comments
Hello. Thank you for your videos and tutorials. Got this error in this task:
ReplyDeletechown failed: failed to look up user $banner", "owner": "root", "path": "/opt/dba/news.tar.gz", "size": 157, "state": "file", "uid": 0}
Did you first check the ansible all -a "ls -ltr /opt/sysops" -i inventory , did you facing any issue. . Error seems to be for stapp03 banner user kindly login on the server and check the file path . Still if you face issue connect me
DeleteHello. Thank you for your videos and tutorials. Got this error in this task:
ReplyDeletechown failed: failed to look up user $banner", "owner": "root", "path": "/opt/dba/news.tar.gz", "size": 157, "state": "file", "uid": 0}