[ansible@ip-172-31-36-60 ~]$ vi playbook1.yml
[ansible@ip-172-31-36-60 ~]$ cat playbook1.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy file on websever1"
command: touch /tmp/raj.txt
[ansible@ip-172-31-36-60 ~]$ ansible-playbook playbook1.yml -i inventory.txt
On client after running playbook
before running
[root@ip-172-31-90-234 tmp]# ls
after running
[root@ip-172-31-90-234 tmp]# ls
raj.txt
[root@ip-172-31-90-234 tmp]#
Creating dummy directory and file
[ansible@ip-172-31-36-60 ~]$ cat playbook1.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy file on websever1"
command: touch /tmp/raj.txt
[ansible@ip-172-31-36-60 ~]$ ansible-playbook playbook1.yml -i inventory.txt
On client after running playbook
before running
[root@ip-172-31-90-234 tmp]# ls
after running
[root@ip-172-31-90-234 tmp]# ls
raj.txt
[root@ip-172-31-90-234 tmp]#
--------------------------------------------------------------------------------------------------------------------
create dirctry on client
Run the below command on master
[ansible@ip-172-31-86-165 ~]$ vi playbook2.yml
[ansible@ip-172-31-86-165 ~]$ cat playbook2.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy directory on websever1"
command: mkdir -p /tmp/raj4
[ansible@ip-172-31-86-165 ~]$ ansible-playbook playbook2.yml -i inventory.txt
PLAY [this is our first playbook.] *************************************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************************************************************
ok: [172.31.95.104]
TASK [create a dummy directory on websever1] ***************************************************************************************************************************
[WARNING]: Consider using the file module with state=directory rather than running mkdir. If you need to use command because file is insufficient you can add
warn=False to this command task or set command_warnings=False in ansible.cfg to get rid of this message.
changed: [172.31.95.104]
PLAY RECAP *************************************************************************************************************************************************************
172.31.95.104 : ok=2 changed=1 unreachable=0 failed=0
[ansible@ip-172-31-86-165 ~]$
Now run the below command on client
[root@ip-172-31-95-104 ~]# cd /tmp
[root@ip-172-31-95-104 tmp]# ls
raj4
[root@ip-172-31-95-104 tmp]#
Run the below command on master
[ansible@ip-172-31-86-165 ~]$ vi playbook2.yml
[ansible@ip-172-31-86-165 ~]$ cat playbook2.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy directory on websever1"
command: mkdir -p /tmp/raj4
[ansible@ip-172-31-86-165 ~]$ ansible-playbook playbook2.yml -i inventory.txt
PLAY [this is our first playbook.] *************************************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************************************************************
ok: [172.31.95.104]
TASK [create a dummy directory on websever1] ***************************************************************************************************************************
[WARNING]: Consider using the file module with state=directory rather than running mkdir. If you need to use command because file is insufficient you can add
warn=False to this command task or set command_warnings=False in ansible.cfg to get rid of this message.
changed: [172.31.95.104]
PLAY RECAP *************************************************************************************************************************************************************
172.31.95.104 : ok=2 changed=1 unreachable=0 failed=0
[ansible@ip-172-31-86-165 ~]$
Now run the below command on client
[root@ip-172-31-95-104 ~]# cd /tmp
[root@ip-172-31-95-104 tmp]# ls
raj4
[root@ip-172-31-95-104 tmp]#
---------------------------------------------------------------------------------------------------------------------
[ansible@ip-172-31-86-165 ~]$ vi playbook3.yml
[ansible@ip-172-31-86-165 ~]$ cat playbook3.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy directory on websever1"
command: mkdir /tmp/raj8
-
name: "creating dummy file in webserver1"
command: touch /tmp/raj8/raj8.txt
[ansible@ip-172-31-86-165 ~]$ ansible-playbook playbook3.yml -i inventory.txt
PLAY [this is our first playbook.] *************************************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************************************************************
ok: [172.31.95.104]
TASK [create a dummy directory on websever1] ***************************************************************************************************************************
[WARNING]: Consider using the file module with state=directory rather than running mkdir. If you need to use command because file is insufficient you can add
warn=False to this command task or set command_warnings=False in ansible.cfg to get rid of this message.
changed: [172.31.95.104]
TASK [creating dummy file in webserver1] *******************************************************************************************************************************
[WARNING]: Consider using the file module with state=touch rather than running touch. If you need to use command because file is insufficient you can add warn=False
to this command task or set command_warnings=False in ansible.cfg to get rid of this message.
changed: [172.31.95.104]
PLAY RECAP *************************************************************************************************************************************************************
172.31.95.104 : ok=3 changed=2 unreachable=0 failed=0
[ansible@ip-172-31-86-165 ~]$
run the below command on client
[root@ip-172-31-95-104 tmp]# ls
raj4 raj8
[root@ip-172-31-95-104 tmp]# cd raj8
[root@ip-172-31-95-104 raj8]# ls
raj8.txt
[root@ip-172-31-95-104 raj8]#
No comments:
Post a Comment