# Executing various commands over a list

**URL:** <https://forum.ansible.com/t/executing-various-commands-over-a-list/14380>\
**Category:** Ansible Project\
**Created:** [January 20, 2014, 4:25am UTC](https://forum.ansible.com/t/executing-various-commands-over-a-list/14380 "2014-01-20T04:25:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gonzalo\_Servat](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Gonzalo\_Servat](https://forum.ansible.com/u/Gonzalo_Servat)\
**Post date:** [January 20, 2014, 4:25am UTC](https://forum.ansible.com/t/executing-various-commands-over-a-list/14380/1 "2014-01-20T04:25:43Z")

</div>

Hi All,

I won’t say “include + with\_items” 😉 but I am looking for a way to run a bunch of commands, sequentially, over a list. For example:

paths:

- [[‘foo:/path/to/dir1’, ‘/dir1’] ]
- [[‘foo:/path/to/dir2’, ‘/dir2’] ]
- etc…

In the playbook, I want to do a set of tasks over these paths… i.e:

- name: create a temporary mount path  
local\_action: command mktemp -d  
register: tempdir
- name: mount directory  
local\_action: shell mount `dirname {{ item.0 }}` {{ tempdir.stdout }}  
_\<do stuff with {{ item.1 }} and tempdir.stdout\>_
- name: umount and delete temporary dir  
local\_action: shell umount {{ tempdir.stdout }} && rm -rf {{ tempdir.stdout }}

Any suggestions on how this can this be achieved?

Thanks.  
GS

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [January 20, 2014, 12:54pm UTC](https://forum.ansible.com/t/executing-various-commands-over-a-list/14380/2 "2014-01-20T12:54:56Z")

</div>

Look up “with\_nested” and “with\_together” in the documentation for how to do nested loops.
