# with\_items passed individually and as list

**URL:** <https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987>\
**Category:** Ansible Project\
**Created:** [June 19, 2013, 12:11pm UTC](https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987 "2013-06-19T12:11:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 19, 2013, 12:11pm UTC](https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987/1 "2013-06-19T12:11:31Z")

</div>

Hello,

I have a simple playbook that just defines an APT task to purge  
packages provided as with\_items list.

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: remove packages  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;apt: pkg={{item}} state=absent purge=yes update\_cache=no  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- puppet  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- puppet-common  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[…]

Running this across a set of hosts, I got the following,  
inconsistent output (abridged):

&nbsp;&nbsp;ok: [diamond.madduck.net] =\> (item=puppet)  
&nbsp;&nbsp;ok: [arnold.madduck.net] =\> (item=puppet)  
&nbsp;&nbsp;ok: [arnold.madduck.net] =\> (item=puppet-common)  
&nbsp;&nbsp;ok: [diamond.madduck.net] =\> (item=puppet-common)  
&nbsp;&nbsp;[…]  
&nbsp;&nbsp;changed: [jugband.madduck.net] =\> (item=puppet,puppet-common,facter,libopenssl-ruby,libshadow-ruby1.8,libxmlrpc-ruby,libruby,libruby1.8,libaugeas-ruby1.8,libdpkg-ruby1.8,libhttp-access2-ruby1.8,libuconv-ruby1.8,libxml-parser-ruby1.8,ri1.8,facter,ruby-json,ruby1.8,ruby-shadow)  
&nbsp;&nbsp;ok: [vizier.madduck.net] =\> (item=puppet,puppet-common,facter,libopenssl-ruby,libshadow-ruby1.8,libxmlrpc-ruby,libruby,libruby1.8,libaugeas-ruby1.8,libdpkg-ruby1.8,libhttp-access2-ruby1.8,libuconv-ruby1.8,libxml-parser-ruby1.8,ri1.8,facter,ruby-json,ruby1.8,ruby-shadow)

That is to say: some hosts iterated through the package list  
one-by-one, while others received a list.

What determines this difference? How can I always pass lists?

Thanks,

---

<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:** [June 19, 2013, 3:13pm UTC](https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987/2 "2013-06-19T15:13:39Z")

</div>

I suspect you are running recent 1.3 code against a 1.2 module directory and the module doesn’t have the WITH\_ITEMS\_WANTS\_LIST string in it, which is the new way we tell modules what they can do in series.

---

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 19, 2013, 4:26pm UTC](https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987/3 "2013-06-19T16:26:57Z")

</div>

also sprach Michael DeHaan \<michael@ansibleworks.com\> [2013.06.19.1713 +0200]:

> I suspect you are running recent 1.3 code against a 1.2 module  
> directory and the module doesn't have the WITH\_ITEMS\_WANTS\_LIST  
> string in it, which is the new way we tell modules what they can  
> do in series.

I am running only from source and there are no modules installed  
anywhere else.

ansible-playbook 1.3 (devel 0bd92d8196) last updated 2013/06/19 17:39:33 (GMT +200)

I verified that the module that gets executed also contains  
WITH\_ITEMS\_WANTS\_LIST

On a playbook run, some hosts produce one ok: line for each  
with\_list item, and other hosts produce one ok: for all items,  
specifying a list.

There are no differences I can see between the hosts, i.e. they all  
run Debian 7.0 with identical Python versions and package sets.

Very curiously, the set of hosts for which the APT runs will display  
individually and the set of hosts displaying lists is non-constant,  
i.e. it differs between runs.

It's weird, isn't it? Could this be a bug or maybe a possible  
control path in the code wasn't updated?

I investigated a bit and especially had a look at what happens at  
lib/ansible/runner/\_\_init\_\_.py:419, and I think I found a symptom:

self.module\_with\_list starts off False for the first batch of $forks  
hosts, and then turns True, so hosts 6 through n will get lists  
passed to the APT module, but hosts 1 through 5 won't.

I suspect that this is a multiprocessing problem. How does the  
runner piece this all together? How can I help debug this further?

Cheers,

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [June 19, 2013, 9:02pm UTC](https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987/4 "2013-06-19T21:02:17Z")

</div>

​possibly [https://github.com/ansible/ansible/pull/3267](https://github.com/ansible/ansible/pull/3267) ?​

---

<div class="post-metadata">

**Author:** ![Scott\_Sturdivant](https://avatars.discourse-cdn.com/v4/letter/s/f14d63/32.png) [@Scott\_Sturdivant](https://forum.ansible.com/u/Scott_Sturdivant)\
**Post date:** [June 19, 2013, 9:06pm UTC](https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987/5 "2013-06-19T21:06:48Z")

</div>

Nah, that’s just a documentation gotcha.

I also am not seeing the expected behavior of a single module execution over a list of items. Digging through the code, I saw that in runner/ **init**.py module\_with\_list was set to True _after_ the module was copied over. I got in over my head and couldn’t figure out how it was supposedly / or should be set prior to executing the copy step. Martin seems to have made more progress than me! 🙂

---

<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:** [June 19, 2013, 9:16pm UTC](https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987/6 "2013-06-19T21:16:05Z")

</div>

I suspect you too are pointing at 1.2 module paths, but I’ll test it.

The 1.3 modules have a WITH\_ITEMS\_AS\_LIST in their resource that allows them to know to merge things together and do everything in one pass.

---

<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:** [June 19, 2013, 10:55pm UTC](https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987/7 "2013-06-19T22:55:29Z")

</div>

I’ve confirmed the 1.3 pull request that intended to streamline this doesn’t quite work.

Working on this, stay tuned 🙂

---

<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:** [June 19, 2013, 11:03pm UTC](https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987/8 "2013-06-19T23:03:35Z")

</div>

Commit reverted, back to normal.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [June 19, 2013, 11:13pm UTC](https://forum.ansible.com/t/with-items-passed-individually-and-as-list/12987/9 "2013-06-19T23:13:30Z")

</div>

mybad! modules worked but I didn’t check that they worked with a list. I didn’t realize they would fall back to single item.
