Ansible Copy Module

Ansible Copy Module

Task :

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/finance/index.html file to all application servers at location /opt/finance.

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 :

[email protected]_host /$ vi /home/thor/ansible/inventory
stapp01 ansible_host=172.16.238.10 [email protected] ansible_user=tony
stapp02 ansible_host=172.16.238.11 [email protected] ansible_user=steve
stapp03 ansible_host=172.16.238.12 ansible_ssh_pass=BigGr33n ansible_user=banner

[email protected]_host /$ vi /home/thor/ansible/playbook.yml
- name: Ansible copy
  hosts: all
  become: yes
  tasks:
    - name: copy file to finance folder
      copy: src=/usr/src/finance/index.html dest=/opt/finance

[email protected]_host /$ cd /home/thor/ansible/
[email protected]_host ~/ansible$ ansible-playbook -i inventory playbook.yml

PLAY [Ansible copy] ********************************************************************

TASK [Gathering Facts] *****************************************************************
ok: [stapp02]
ok: [stapp01]
ok: [stapp03]

TASK [copy file to finance folder] *****************************************************
changed: [stapp02]
changed: [stapp01]
changed: [stapp03]

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

Leave a Reply

Your email address will not be published. Required fields are marked *