Copy Data to App Servers using Ansible Level 1 Ansible KodeKloud Engineer Task Success

Ticker

6/recent/ticker-posts

Copy Data to App Servers using Ansible Level 1 Ansible KodeKloud Engineer Task Success

 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.

Please Note:-  Perform the below commands based on your question server,  user name & other details that might differ. So please read the task carefully before executing it. All the Best 👍

Solution:  

1Go 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$


3.  Check the inventory file is working correctly by listing folder on all the app servers

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$


4. Create a playbook as per the task  ( refer to Video below for clarity )
 

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$


6. validate the task by running the below command
      

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$



7. Click on Finish & Confirm to complete the task successful

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , please go through and share your comments. Like and share the knowledge

Post a Comment

0 Comments

Latest Posts

Copy Data to App Servers using Ansible Level 1 Ansible KodeKloud Engineer Task Success