Friday, 9 August 2019

Ansible Copy Modules by Raj Gupta

1. Copy Module

Run the below command on master

[ansible@ip-172-31-95-179 ~]$ vi playbook1.yml
[ansible@ip-172-31-95-179 ~]$ cat playbook1.yml
-
  name: "this is our first playbook."
  hosts: all
  tasks:
    -
      name: "create a dummy file on websever1"
      copy: src=test.yml dest=/tmp/
[ansible@ip-172-31-95-179 ~]$ vi test.yml
[ansible@ip-172-31-95-179 ~]$ ls
inventory.txt  playbook1.yml  test.yml
[ansible@ip-172-31-95-179 ~]$ ansible-playbook playbook1.yml -i inventory.txt

PLAY [this is our first playbook.] *************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
ok: [172.31.84.42]

TASK [create a dummy file on websever1] ********************************************************************************************************************************
changed: [172.31.84.42]

PLAY RECAP *************************************************************************************************************************************************************
172.31.84.42               : ok=2    changed=1    unreachable=0    failed=0

[ansible@ip-172-31-95-179 ~]$


Now run the below command on client

[root@ip-172-31-84-42 ~]# cd /tmp
[root@ip-172-31-84-42 tmp]# ls
test.yml
[root@ip-172-31-84-42 tmp]#


--------------------------------------------------------------------------------------------------------

[ansible@ip-172-31-95-179 ~]$ vi playbook2.yml
[ansible@ip-172-31-95-179 ~]$ cat playbook2.yml
-
  name: "this is our first playbook."
  hosts: all
  tasks:
    -
      name: "create a dummy file on websever1"
      copy: src=test.yml dest=/tmp/ owner=ansible group=ansible mode=0644
[ansible@ip-172-31-95-179 ~]$ ansible-playbook playbook2.yml -i inventory.txt

PLAY [this is our first playbook.] *************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************
ok: [172.31.84.42]

TASK [create a dummy file on websever1] ********************************************************************************************************************************
changed: [172.31.84.42]

PLAY RECAP *************************************************************************************************************************************************************
172.31.84.42               : ok=2    changed=1    unreachable=0    failed=0

[ansible@ip-172-31-95-179 ~]$

Now Run the below command on client 

[root@ip-172-31-84-42 tmp]# ls -l
total 4
-rw-r--r-- 1 ansible ansible 16 Aug  9 10:06 test.yml
[root@ip-172-31-84-42 tmp]#

User and Group both are ansible in this case and permission is 0644





No comments:

Post a Comment