# Finally fixed, vars\_files and with\_items now 100% compatible

**URL:** <https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683>\
**Category:** Ansible Project\
**Created:** [July 14, 2012, 11:29pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683 "2012-07-14T23:29:09Z")\
**Posts on this page:** 12\
**Page:** 1

<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:** [July 14, 2012, 11:29pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/1 "2012-07-14T23:29:09Z")

</div>

Devel branch update.

I've finally fixed with\_items (better) such that there should be no  
more confusion about not being able to use vars\_files to conditionally  
load host specific files, and use those later in with\_items.

Essentially before with\_items was a macro that created tasks. Now  
it's not a macro anymore, what it does is just loop over many things  
from inside the core "Runner" code, and then returns as if there was  
only one module call.

The code needs cleanup from me yet, but it's pushed, and you should be  
able to test away.

Easiest thing to do is, assuming a file  
packages\_by\_hostname/$hostname.yml containing:

---

<div class="post-metadata">

**Author:** ![John\_Callender](https://avatars.discourse-cdn.com/v4/letter/j/b5ac83/32.png) [@John\_Callender](https://forum.ansible.com/u/John_Callender)\
**Post date:** [July 15, 2012, 5:54pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/2 "2012-07-15T17:54:54Z")

</div>

Someday I will get tired of whining for a page in the Ansible docs that focuses on all the ins and outs of variables, with examples, and will just create such a page. It will be lame, because my understanding of the subject is incomplete, but then someone who knows better will fix it up, and then (frabjous day) I will have what I want. Except by then I’ll have been forced to learn the answers already, so I will no longer need it. Sigh.

Seriously, though: I will make a point of carving out some time to do more than whining about this, and actually put together at least an outline I can post for feedback. In the meantime, though, I’d suggest that the pestering you’ve endured about variables is not just telling you that the functionality could be improved (though it’s awesome that you’ve done that) but also that there’s an opportunity for improved docs in that area.

---

<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:** [July 15, 2012, 6:24pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/3 "2012-07-15T18:24:11Z")

</div>

> Seriously, though: I will make a point of carving out some time to do more than whining about this, and actually put together at least an outline I can post for feedback. In the meantime, though, I'd suggest that the pestering you've endured about variables is not just telling you that the functionality could be improved (though it's awesome that you've done that) but also that there's an opportunity for improved docs in that area.

Don't think it's needed anymore, by making all the things people try more or less possible -- which I've done this weekend -- there is no need to document what may not be clear.

People skim docs, they don't read them totally. The goal here is to prevent the question from even being asked.

In this case, my question to you is, what still don't you think you know?

---

<div class="post-metadata">

**Author:** ![Dave\_Hatton](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@Dave\_Hatton](https://forum.ansible.com/u/Dave_Hatton)\
**Post date:** [July 15, 2012, 8:29pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/4 "2012-07-15T20:29:12Z")

</div>

looks like this has broken the fetch code

seems to be passing in “$item” rather then the file name as src

eg

TASK: [fetch src=$item dest=/data/transit/configs] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[jabber.starground.co.uk](http://jabber.starground.co.uk)] =\> {“changed”: false, “msg”: “missing remote file”}  
ok: [[zabbix.starground.co.uk](http://zabbix.starground.co.uk)] =\> {“changed”: false, “msg”: “missing remote file”}  
ok: [[office.starground.co.uk](http://office.starground.co.uk)] =\> {“changed”: false, “msg”: “missing remote file”}

---

<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:** [July 15, 2012, 8:41pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/5 "2012-07-15T20:41:46Z")

</div>

I'm assuming you mean fetch using with\_items. Very likely as I don't think there's an example of that in examples/, nor a unit test.

Will take a look shortly, shouldn't be difficult.

---

<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:** [July 15, 2012, 9:12pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/6 "2012-07-15T21:12:22Z")

</div>

Fixed pushed, had the multiball code one level too low in the stack, and also tweaked the unilateral phase detractors to improve the magneto reluctance.

---

<div class="post-metadata">

**Author:** ![Dave\_Hatton](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@Dave\_Hatton](https://forum.ansible.com/u/Dave_Hatton)\
**Post date:** [July 15, 2012, 10:10pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/7 "2012-07-15T22:10:28Z")

</div>

Thanks, I’ll take a look in the morning. Very late here.

Also noticed “ssh.” is missing from ./lib/ansible/runner/connection/ **init**.py

conn = ssh.SSHConnection(self.runner, host, port)

---

<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:** [July 15, 2012, 10:18pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/8 "2012-07-15T22:18:57Z")

</div>

Also fixed, thanks

---

<div class="post-metadata">

**Author:** ![Mark\_Theunissen](https://avatars.discourse-cdn.com/v4/letter/m/898d66/32.png) [@Mark\_Theunissen](https://forum.ansible.com/u/Mark_Theunissen)\
**Post date:** [July 16, 2012, 9:49pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/9 "2012-07-16T21:49:52Z")

</div>

I tested this change and it seems to have broken something. Test playbook action:

- name: Installing required package $item for the controller stack  
action: apt pkg=$item state=installed  
with\_items:
- nginx
- php5-fpm
- unzip
- python-mysqldb

Previously this would show:

TASK: [Installing required package nginx for the controller stack] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1]

TASK: [Installing required package php5-fpm for the controller stack] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1]

TASK: [Installing required package unzip for the controller stack] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1]

TASK: [Installing required package python-mysqldb for the controller stack] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1]

Now the output is different and $item is not being substituted properly:

TASK: [Installing required package $item for the controller stack] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1]  
ok: [127.0.0.1]  
ok: [127.0.0.1]  
ok: [127.0.0.1]

Thanks

- Mark

---

<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:** [July 16, 2012, 11:23pm UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/10 "2012-07-16T23:23:12Z")

</div>

This part is actually 100% fine -- which is irrelevant to the parts I'm actually fixing ATM (mostly about inventory variables not getting passed down, about done)

Notice the 5 oks? The name of the task is not going to be substituted anymore, and it runs 5 commands, but only  
makes 1 task. You didn't get any failures, so that's a good thing.

---

<div class="post-metadata">

**Author:** ![John\_Callender](https://avatars.discourse-cdn.com/v4/letter/j/b5ac83/32.png) [@John\_Callender](https://forum.ansible.com/u/John_Callender)\
**Post date:** [July 17, 2012, 1:01am UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/11 "2012-07-17T01:01:55Z")

</div>

I noticed that happening, too (the with\_items producing just a list of oks, rather than full output for the task iteration with $item replaced with the list item). I wasn’t sure if it was intentional or not, but it sounds from this comment like it was.

Maybe it’s just because I got used to the old behavior, but I felt like this output is a little less clear about what is actually going on. If there are benefits to the new behavior I’m sure I can get used to this style of output as well, but at least at the moment it feels like a small step backward to lose visibility into each individual item being explicitly iterated over.

---

<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:** [July 17, 2012, 1:06am UTC](https://forum.ansible.com/t/finally-fixed-vars-files-and-with-items-now-100-compatible/11683/12 "2012-07-17T01:06:42Z")

</div>

I'm not against output upgrades, I'm just saying it's not at all busted. If you run with --verbose you can pretty easily tell what is going on.

patches would be considered.
