I have a list of 6 files; if any of them exist already, I need to delete it. If none of them exist just keep going. What I have below is giving me errors that ‘tmp_files.stat.exists is false’. Here is what I have:
all loop items will be set into the disired state (absent).
If that state is reached (file is ‘absent’) Ansible is happy and won’t do anything.
If that state is not reached (file is not ‘absent’) Ansible will make sure the state is there (aka remove the file)
If you want to define those files elsewehere then in the playbook itself you can also create a variable and then just put the variable in the path line (where now {{ item }} is set
the below example requires that your local user (with whom you are running the playbook) has sufficient privilegdes to remove files in your path location.
If not, you’ll have to add