# In playbook interate over a hash to rm files

**URL:** <https://forum.ansible.com/t/in-playbook-interate-over-a-hash-to-rm-files/15077>\
**Category:** Ansible Project\
**Created:** [April 23, 2014, 7:55pm UTC](https://forum.ansible.com/t/in-playbook-interate-over-a-hash-to-rm-files/15077 "2014-04-23T19:55:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenton\_Brede](https://avatars.discourse-cdn.com/v4/letter/k/db5fbb/32.png) [@Kenton\_Brede](https://forum.ansible.com/u/Kenton_Brede)\
**Post date:** [April 23, 2014, 7:55pm UTC](https://forum.ansible.com/t/in-playbook-interate-over-a-hash-to-rm-files/15077/1 "2014-04-23T19:55:53Z")

</div>

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

`

---

<div class="post-metadata">

**Author:** ![Strahinja\_Kustudic2](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Strahinja\_Kustudic2](https://forum.ansible.com/u/Strahinja_Kustudic2)\
**Post date:** [April 23, 2014, 9:09pm UTC](https://forum.ansible.com/t/in-playbook-interate-over-a-hash-to-rm-files/15077/2 "2014-04-23T21:09:47Z")

</div>

Check out looping over subelements [http://docs.ansible.com/playbooks\_loops.html#looping-over-subelements](http://docs.ansible.com/playbooks_loops.html#looping-over-subelements)

---

<div class="post-metadata">

**Author:** ![Adam\_Morris](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@Adam\_Morris](https://forum.ansible.com/u/Adam_Morris)\
**Post date:** [April 23, 2014, 9:51pm UTC](https://forum.ansible.com/t/in-playbook-interate-over-a-hash-to-rm-files/15077/3 "2014-04-23T21:51:03Z")

</div>

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
