Ansible Archive Module Kodekloud

 

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.

    Create an archive games.tar.gz (make sure archive format is tar.gz) of /usr/src/finance/ directory ( present on each app server ) and copy it to /opt/finance/ directory on all app servers. The user and group owner of archive games.tar.gz should be tony for App Server 1, steve for App Server 2 and banner for App Server 3.

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.


Solution:

Go to ansible folder

cd /home/thor/ansible 

Then Create the playbook.yml file according to question

vi 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/finance/
dest: /opt/finance/games.tar.gz
format: gz
force_archive: true
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"

 Then run the ansible command

ansible-playbook  -i inventory playbook.yml

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment