# Problem with: yum module, with\_items, composite-variable

**URL:** <https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439>\
**Category:** Ansible Project\
**Created:** [March 1, 2013, 6:48pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439 "2013-03-01T18:48:41Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asad\_Khan](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@Asad\_Khan](https://forum.ansible.com/u/Asad_Khan)\
**Post date:** [March 1, 2013, 6:48pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/1 "2013-03-01T18:48:41Z")

</div>

Variable resolution seems to fail on the second iteration of a with\_items used with yum, but only if the variable is “composite” i.e. an expression involving other variables.

Here is the playbook:

vars:  
pkg\_list:

- jdk
- httpd

pkg\_versions: { “jdk”: “1.6.0\_31-fcs”, “httpd”: “2.2.15-15.el6.centos.1” }

tasks:

- name: Composite-Variable resolution works fine with the copy module  
action: copy src=/tmp/${item}-${pkg\_versions.${item}} dest=/tmp  
with\_items: ${pkg\_list}

- name: … but does not work with the yum module  
action: yum pkg=${item}-${pkg\_version.${item}} state=installed ## This doesn’t work  
#action: yum pkg=${item} state=installed ## This works  
with\_items: ${pkg\_list}

The output is:

[ansible@dev-autoserver-01 ~]$ ansible-playbook /etc/ansible/sys-plays/testyumbug.yml -v

PLAY [Test Playbook] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.120.210.61]

TASK: [Composite-Variable resolution works fine with the copy module] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.120.210.61] =\> (item=jdk) =\> {“changed”: false, “dest”: “/tmp/jdk-1.6.0\_31-fcs”, “group”: “root”, “item”: “jdk”, “md5sum”: “d41d8cd98f00b204e9800998ecf8427e”, “mode”: “0644”, “owner”: “root”, “src”: “/home/ansible/.ansible/tmp/ansible-1362162055.67-15730396780203/jdk-1.6.0\_31-fcs”, “state”: “file”}  
ok: [10.120.210.61] =\> (item=httpd) =\> {“changed”: false, “dest”: “/tmp/httpd-2.2.15-15.el6.centos.1”, “group”: “root”, “item”: “httpd”, “md5sum”: “d41d8cd98f00b204e9800998ecf8427e”, “mode”: “0644”, “owner”: “root”, “src”: “/home/ansible/.ansible/tmp/ansible-1362162056.13-226327540995443/httpd-2.2.15-15.el6.centos.1”, “state”: “file”}

TASK: [… but does not work with the yum module] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [10.120.210.61] =\> (item=jdk,httpd) =\> {“changed”: true, “failed”: true, “item”: “jdk,httpd”, “rc”: 0, “results”: [“\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n jdk x86\_64 2000:1.6.0\_38-fcs srt 56 M\n\nTransaction Summary\n================================================================================\nInstall 1 Package(s)\n\nTotal download size: 56 M\nInstalled size: 121 M\nUnpacking JAR files…\n\trt.jar…\n\tjsse.jar…\n\tcharsets.jar…\n\ttools.jar…\n\tlocaledata.jar…\n\tplugin.jar…\n\tjavaws.jar…\n\tdeploy.jar…\n\nInstalled:\n jdk.x86\_64 2000:1.6.0\_38-fcs \n\n”]}  
msg: No Package matching ‘httpd-${pkg\_version.${item}}’ found available, installed or updated

FATAL: all hosts have already failed – aborting

I don’t have a workaround yet, other than to either try to debug the yum module, or code my own replacement module.  
(The above is a completely contrived example just to reproduce the issue - the actual use-case is more involved and involves proprietary rpm’s; it’s not feasible to unroll the loop - I need to work with a list )

---

<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:** [March 1, 2013, 7:02pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/2 "2013-03-01T19:02:24Z")

</div>

It just looks like something is missing in your hash to me. Here's a  
much much cleaner way to do that:

vars:  
&nbsp;&nbsp;packages:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- { name: 'foo', version: 'xyz' }  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- { name: 'bar', version: 'xyz' }

tasks:  
&nbsp;&nbsp;&nbsp;- yum: name=${item.name}-${item.version} state=installed  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: $packages

In general, when you start to use variables in ways where they all  
nest like that, it's time to simplify things. Ansible playbooks  
should be very easy to read.

---

<div class="post-metadata">

**Author:** ![Asad\_Khan](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@Asad\_Khan](https://forum.ansible.com/u/Asad_Khan)\
**Post date:** [March 1, 2013, 8:18pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/3 "2013-03-01T20:18:13Z")

</div>

I’m on 1.0, and I experimented with your suggestion:

vars:  
pkgs:

- { name: “jdk”, version: “1.6.0\_31-fcs” }
- { name: “httpd”, version: “2.2.15-15.el6.centos.1” }

tasks:

- name: New style variable resolution  
action: copy src=/tmp/${item.name}-${item.version} dest=/tmp  
with\_items: $pkgs

- name: … but does not work with the yum module  
action: yum name=${item.name}-${item.version} state=installed  
with\_items: $pkgs

I got the following:

LAY [Test Playbook] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.120.210.61]

TASK: [New style variable resolution] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [10.120.210.61] =\> (item={‘version’: ‘1.6.0\_31-fcs’, ‘name’: ‘jdk’}) =\> {“changed”: false, “dest”: “/tmp/jdk-1.6.0\_31-fcs”, “group”: “root”, “item”: {“name”: “jdk”, “version”: “1.6.0\_31-fcs”}, “md5sum”: “d41d8cd98f00b204e9800998ecf8427e”, “mode”: “0644”, “owner”: “root”, “src”: “/home/ansible/.ansible/tmp/ansible-1362168335.16-67188730965918/jdk-1.6.0\_31-fcs”, “state”: “file”}  
ok: [10.120.210.61] =\> (item={‘version’: ‘2.2.15-15.el6.centos.1’, ‘name’: ‘httpd’}) =\> {“changed”: false, “dest”: “/tmp/httpd-2.2.15-15.el6.centos.1”, “group”: “root”, “item”: {“name”: “httpd”, “version”: “2.2.15-15.el6.centos.1”}, “md5sum”: “d41d8cd98f00b204e9800998ecf8427e”, “mode”: “0644”, “owner”: “root”, “src”: “/home/ansible/.ansible/tmp/ansible-1362168335.63-42039443662886/httpd-2.2.15-15.el6.centos.1”, “state”: “file”}

TASK: [… but does not work with the yum module] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [10.120.210.61] =\> Traceback (most recent call last):  
File “/usr/lib/python2.6/site-packages/ansible/runner/ **init**.py”, line 237, in \_executor  
exec\_rc = self.\_executor\_internal(host)  
File “/usr/lib/python2.6/site-packages/ansible/runner/ **init**.py”, line 287, in \_executor\_internal  
inject[‘item’] = “,”.join(items)  
TypeError: sequence item 0: expected string, dict found

FATAL: all hosts have already failed – aborting

Could this be a 1.0 vs 1.1 issue?

---

<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:** [March 1, 2013, 8:37pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/4 "2013-03-01T20:37:28Z")

</div>

There is no 1.1 issue, I just gave you a bad example syntax.

name="foo=1.0"

Not a dash.

---

<div class="post-metadata">

**Author:** ![Daniel\_Hokka\_Zakriss](https://avatars.discourse-cdn.com/v4/letter/d/f05b48/32.png) [@Daniel\_Hokka\_Zakriss](https://forum.ansible.com/u/Daniel_Hokka_Zakriss)\
**Post date:** [March 1, 2013, 9:29pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/5 "2013-03-01T21:29:51Z")

</div>

Asad Khan wrote:

> I'm on 1.0, and I experimented with your suggestion:
> 
> &nbsp;&nbsp;vars:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pkgs:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- { name: "jdk", version: "1.6.0\_31-fcs" }  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- { name: "httpd", version: "2.2.15-15.el6.centos.1" }
> 
> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: New style variable resolution  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action: copy src=/tmp/${item.name}-${item.version} dest=/tmp  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: $pkgs
> 
> &nbsp;&nbsp;&nbsp;&nbsp;- name: .. but does not work with the yum module  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action: yum name=${item.name}-${item.version} state=installed  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_items: $pkgs
> 
> I got the following:
> 
> LAY [Test Playbook] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [10.120.210.61]
> 
> TASK: [New style variable resolution] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> ok: [10.120.210.61] =\> (item={'version': '1.6.0\_31-fcs', 'name': 'jdk'})  
> =\>  
> {"changed": false, "dest": "/tmp/jdk-1.6.0\_31-fcs", "group": "root",  
> "item": {"name": "jdk", "version": "1.6.0\_31-fcs"}, "md5sum":  
> "d41d8cd98f00b204e9800998ecf8427e", "mode": "0644", "owner": "root",  
> "src":  
> "/home/ansible/.ansible/tmp/ansible-1362168335.16-67188730965918/jdk-1.6.0\_31-fcs",  
> "state": "file"}  
> ok: [10.120.210.61] =\> (item={'version': '2.2.15-15.el6.centos.1', 'name':  
> 'httpd'}) =\> {"changed": false, "dest":  
> "/tmp/httpd-2.2.15-15.el6.centos.1", "group": "root", "item": {"name":  
> "httpd", "version": "2.2.15-15.el6.centos.1"}, "md5sum":  
> "d41d8cd98f00b204e9800998ecf8427e", "mode": "0644", "owner": "root",  
> "src":  
> "/home/ansible/.ansible/tmp/ansible-1362168335.63-42039443662886/httpd-2.2.15-15.el6.centos.1",  
> "state": "file"}
> 
> TASK: [.. but does not work with the yum module] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [10.120.210.61] =\> Traceback (most recent call last):  
> &nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/ansible/runner/\_\_init\_\_.py", line  
> 237, in \_executor  
> &nbsp;&nbsp;&nbsp;&nbsp;exec\_rc = self.\_executor\_internal(host)  
> &nbsp;&nbsp;File "/usr/lib/python2.6/site-packages/ansible/runner/\_\_init\_\_.py", line  
> 287, in \_executor\_internal  
> &nbsp;&nbsp;&nbsp;&nbsp;inject['item'] = ",".join(items)  
> TypeError: sequence item 0: expected string, dict found

This is from the yum/apt optimization for with\_items. Can you file an issue  
on Github for it?

Daniel

---

<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:** [March 1, 2013, 9:33pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/6 "2013-03-01T21:33:31Z")

</div>

> This is from the yum/apt optimization for with\_items. Can you file an issue  
> on Github for it?

While this is the root cause, it doesn't detract from that being  
something we can simplify and not even get into that corner 🙂

---

<div class="post-metadata">

**Author:** ![Asad\_Khan](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@Asad\_Khan](https://forum.ansible.com/u/Asad_Khan)\
**Post date:** [March 1, 2013, 9:38pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/7 "2013-03-01T21:38:24Z")

</div>

OK, doing so

---

<div class="post-metadata">

**Author:** ![Asad\_Khan](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@Asad\_Khan](https://forum.ansible.com/u/Asad_Khan)\
**Post date:** [March 1, 2013, 9:53pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/8 "2013-03-01T21:53:15Z")

</div>

Ticket here:

[https://github.com/ansible/ansible/issues/2258](https://github.com/ansible/ansible/issues/2258)

---

<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:** [March 1, 2013, 11:33pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/9 "2013-03-01T23:33:57Z")

</div>

Fixed! Yeah the with\_items optimization shouldn't run in this case.  
And now it doesn't, you should be good to go!

---

<div class="post-metadata">

**Author:** ![Asad\_Khan](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@Asad\_Khan](https://forum.ansible.com/u/Asad_Khan)\
**Post date:** [March 2, 2013, 2:11am UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/10 "2013-03-02T02:11:00Z")

</div>

Nice. I will test this out soon, thank you!

---

<div class="post-metadata">

**Author:** ![Dmitry\_Horbach](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@Dmitry\_Horbach](https://forum.ansible.com/u/Dmitry_Horbach)\
**Post date:** [June 7, 2013, 12:45pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/11 "2013-06-07T12:45:59Z")

</div>

Hi,

I have a slightly different case - I’m trying to composite package name with full path to RPM

> - name: installing required packages  
> action: yum name=$tmp\_dir/$item state=installed  
> with\_items:
> - packageA.rpm
> - packageB.rpm  
> sudo: yes

Name will be resolved as /tmp/packageA.rpm,packageB.rpm which correctly resolves only for the first package.

Is there any better way to install multiple rpm’s using absolute path?

---

<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 7, 2013, 3:23pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/12 "2013-06-07T15:23:08Z")

</div>

The yum module automatically combines with\_items to avoid multiple transactions, so no, that won’t work.

Since you are installing local RPMs, switch to the command or shell module and call RPM, perhaps.

–Michael

---

<div class="post-metadata">

**Author:** ![Seth\_Vidal](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Seth\_Vidal](https://forum.ansible.com/u/Seth_Vidal)\
**Post date:** [June 7, 2013, 9:22pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/13 "2013-06-07T21:22:18Z")

</div>

OR do this:  
- name: installing required packages  
&nbsp;&nbsp;action: yum name=$item state=installed  
&nbsp;&nbsp;with\_items:  
&nbsp;&nbsp;&nbsp;&nbsp;- $tmp\_dir/packageA.rpm  
&nbsp;&nbsp;&nbsp;&nbsp;- $tmp\_dir/packageB.rpm  
&nbsp;&nbsp;sudo: yes

-sv

---

<div class="post-metadata">

**Author:** ![Dmitry\_Horbach](https://avatars.discourse-cdn.com/v4/letter/d/c6cbf5/32.png) [@Dmitry\_Horbach](https://forum.ansible.com/u/Dmitry_Horbach)\
**Post date:** [June 11, 2013, 12:12pm UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/14 "2013-06-11T12:12:26Z")

</div>

Thanks for suggestions.  
Initially i was using with\_items: - $tmp\_dir/packageA.rpm but this gives a lot of duplicated prefixes.  
Also as I try to move all configuration items into vars files I ended up with nice sets which can be overriden on role level.

vars:

```auto

> set_version: 8
> rpmset_8:
> - packageA.rpm
> - packageB.rpm
> rpmset: $rpmset_{{ set_version }}

 
task:  

> - name: installing rpms
> command: /bin/rpm -Uhv $tmp_dir/{{ item }}
> with_items: $rpmset

```

Drawback - multiple transactions. Can yum module support something optional like chdir parameter?

---

<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 12, 2013, 10:44am UTC](https://forum.ansible.com/t/problem-with-yum-module-with-items-composite-variable/12439/15 "2013-06-12T10:44:31Z")

</div>

No chdir parameter.

I would go with Seth’s suggestion above as it solves the with\_items question, and also does one transaction.
