# Multiple actions in playbook?

**URL:** <https://forum.ansible.com/t/multiple-actions-in-playbook/13599>\
**Category:** Ansible Project\
**Created:** [October 3, 2013, 6:00am UTC](https://forum.ansible.com/t/multiple-actions-in-playbook/13599 "2013-10-03T06:00:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yaniv\_Kaul](https://avatars.discourse-cdn.com/v4/letter/y/bc79bd/32.png) [@Yaniv\_Kaul](https://forum.ansible.com/u/Yaniv_Kaul)\
**Post date:** [October 3, 2013, 6:00am UTC](https://forum.ansible.com/t/multiple-actions-in-playbook/13599/1 "2013-10-03T06:00:40Z")

</div>

I’d like to perform the following:

- Ensure 3 results file do not exist on targets
- Run a script that produces them on targets
- Copy the 3 resulting files back.
- Delete the 3 resulting file from targets.

Seems like I can’t do something like (for the removal process):

name: remove 3 results file from target:  
file: dest={{ res\_file1 }} state=absent  
file: dest={{ res\_file2 }} state=absent

file: dest={{ res\_file3 }} state=absent

But I need to perform:

name: remove results file 1 from target  
file: dest={{ res\_file1 }} state=absent  
name: remove results file 2 from target

file: dest={{ res\_file2 }} state=absent

name: remove results file 3 from target

file: dest={{ res\_file3 }} state=absent

Am I expected to use ‘with’ ? Any better way (this is quite tedious) ?

ansible-1.2.3-2.el6.noarch on CentOS 6.4.

TIA,  
Y.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 3, 2013, 7:28am UTC](https://forum.ansible.com/t/multiple-actions-in-playbook/13599/2 "2013-10-03T07:28:54Z")

</div>

Yes.

Please read the documentation about with\_items, as follows:

- file: dest={{ item }} state=absent

with\_items:

- res\_file1
- res\_file2
- res\_file3

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [October 3, 2013, 7:38am UTC](https://forum.ansible.com/t/multiple-actions-in-playbook/13599/3 "2013-10-03T07:38:52Z")

</div>

quick update, you will want to template them if you have variables defined.

with\_items:

- “{{ res\_file1 }}”
- “{{ res\_file2 }}”

of course, but can just also do this:

with\_items: list\_of\_files\_to\_delete

where this allows you define that list in inventory, vars\_files, roles, or other places.

I recommend being on 1.3.X though to make sure you have the latest updates.

---

<div class="post-metadata">

**Author:** ![Yaniv\_Kaul](https://avatars.discourse-cdn.com/v4/letter/y/bc79bd/32.png) [@Yaniv\_Kaul](https://forum.ansible.com/u/Yaniv_Kaul)\
**Post date:** [October 3, 2013, 8:29am UTC](https://forum.ansible.com/t/multiple-actions-in-playbook/13599/4 "2013-10-03T08:29:07Z")

</div>

‘with\_items’ is a keyword? I was puzzled a bit about the ‘item’ vs. ‘items’ in the documentation.

If there’s an RPM of 1.3, I’d be happy to take it. Otherwise, it’ll take bit more work to bring it to 1.3, but I’ll try.

Thanks!  
Y.

---

<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:** [October 3, 2013, 12:17pm UTC](https://forum.ansible.com/t/multiple-actions-in-playbook/13599/5 "2013-10-03T12:17:07Z")

</div>

Hi Yaniv,

“with\_items” is covered in the looping sections of the playbook docs – I’d link to them, but it’s currently under a refactor so this link will change tomorrow 🙂

“item” is the value being looped over in each iteration of the with items part.
