In playbook interate over a hash to rm files

Just starting out with Ansible. Currently I’ve got:

`

Check out looping over subelements http://docs.ansible.com/playbooks_loops.html#looping-over-subelements

This could get unwieldy quickly but is there some reason why you can’t use…

  • name: remove files
    file: path={{ item }} state=absent
    with_items:
  • ‘/root/testing’
  • ‘/root/testing2’
  • ‘/home/user/testfile’
  • ‘/home/user/testfile2’

This has the big advantage over the commands version that it is actually idempotent. If it has to remove the files it will, but if they are already gone it will report that the task was ‘OK’. Your version might well report failed if the file no longer exists.

Adam