lineinfile Modules :- This modules are used for to add a new line to file if and only if that line are not there in file. in other word this modules are used to avoid duplicate entry in file.
[ansible@ip-172-31-95-179 ~]$ cat playbook3.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy file on websever1"
lineinfile: path=/tmp/test.txt line="Raj"
[ansible@ip-172-31-95-179 ~]$ ansible-playbook playbook3.yml -i inventory.txt
[ansible@ip-172-31-95-179 ~]$ cat playbook3.yml
-
name: "this is our first playbook."
hosts: all
tasks:
-
name: "create a dummy file on websever1"
lineinfile: path=/tmp/test.txt line="Raj"
[ansible@ip-172-31-95-179 ~]$ ansible-playbook playbook3.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
[ansible@ip-172-31-84-42 tmp]$ cat test.txt
You are welcome
Raj
[ansible@ip-172-31-84-42 tmp]$
No comments:
Post a Comment