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 )