Is there a ad hoc idiomatic syntax to do that in Ansible, ie manage the content of a file if a variable is defined or remove the file if the same variable is not defined?
Or maybe this is the good way to do that?
- name: manage the content of /tmp/foo.txt
template:
src: foo.txt.j2
dest: /tmp/foo.txt
owner: root
group: root
mode: '0644'
when: foo_var is not none
- name: ensure the file /tmp/foo.txt is absent
file:
state: absent
path: /tmp/foo.txt
when: foo_var is none