Stating task status

When creating files, setting up configuration, or managing services, an Ansible user should always state the status of the object of the task, even when the change is aimed at its default value. Even though this will add an extra line to most of your tasks, it is a good habit to have. It is one of those practices that some people think is useless, but for debugging purposes, or for anyone reading your script, seeing the status of each task provides a better view of what each task has done. Naming the task indicates what you want it to do, but it does not necessarily mean that the task has done that action. Using the state option, however, gives a much clearer indication in this respect:

  tasks:
- name: create a new file
file:
path: /usr/local/projects/vars.txt
state: present

- name: removing line to a file
lineinfile:
path: /usr/local/projects/conf.txt
line: "adminuser = user0"
state: absent
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.193.172