# yum module fails to install multiple packages

**URL:** <https://forum.ansible.com/t/yum-module-fails-to-install-multiple-packages/19951>\
**Category:** Ansible Project\
**Created:** [December 7, 2015, 4:37pm UTC](https://forum.ansible.com/t/yum-module-fails-to-install-multiple-packages/19951 "2015-12-07T16:37:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.ansible.com/u/user66)\
**Post date:** [December 7, 2015, 4:37pm UTC](https://forum.ansible.com/t/yum-module-fails-to-install-multiple-packages/19951/1 "2015-12-07T16:37:14Z")

</div>

Name : ansible  
Version : 1.9.2

I’ve got a simple play

`

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.ansible.com/u/user66)\
**Post date:** [December 7, 2015, 4:44pm UTC](https://forum.ansible.com/t/yum-module-fails-to-install-multiple-packages/19951/2 "2015-12-07T16:44:41Z")

</div>

Okay  
I found this

> <https://github.com/ansible/ansible/issues/9552>
>
> Hi! Let's have a playbook like these:
> 
> \`\`\` yaml
> \- hosts: all
> sudo: yes
> tasks…:
> - name: Reproduce items bug
> yum: name=nagios-plugins-{{ item }} state=present
> with\_items:
> - dhcp
> - disc
> - dummy
> \`\`\`
> 
> and if you run this playbook, you can see an error:
> 
> \> failed: \[mylovelyhost\] =\> (item=dhcp,disc,dummy) =\> {"changed": false, "failed": true, "item": "dhcp,disc,dummy", "rc": 0, "results": \["nagios-plugins-dhcp-1.4.16-10.fc20.x86\_64 providing nagios-plugins-dhcp is already installed"\]}
> \> msg: No Package matching 'disc' found available, installed or updated
> 
> So, string concatenation with {{ item }} variable in with\_items cycle will only work for the first step. For next steps only pure {{ item }} will sended.

and the solution is to specify full package name in with\_items

what the hell.. it’s not a solution at all

I wanted to use some var as a package name prefix because  
on Fedora and Red Hat systems

# yum install tfm-rubygem-foreman\_discovery

on on Debian and Ubuntu systems.

# apt-get install ruby-foreman-discovery

f  
I’d like to write a multi-platform code.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [December 7, 2015, 9:04pm UTC](https://forum.ansible.com/t/yum-module-fails-to-install-multiple-packages/19951/3 "2015-12-07T21:04:08Z")

</div>

Right, i’d suggest you have 2 dicts or lists - one for Debians and one for EL linuxes - and conditionally load them into the yum: task based on ansible\_os\_family.

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.ansible.com/u/user66)\
**Post date:** [December 7, 2015, 10:38pm UTC](https://forum.ansible.com/t/yum-module-fails-to-install-multiple-packages/19951/4 "2015-12-07T22:38:03Z")

</div>

You don’t get it.  
Plugins are optional.  
They may or may not be wanted by user.

So I pushed to my repo the code that breaks just to illustrate want I’d like to achieve with ansible  
[https://github.com/kostyrevaa/ansible-role-foreman](https://github.com/kostyrevaa/ansible-role-foreman)

We’ve got vars  
for Ubuntu [https://github.com/kostyrevaa/ansible-role-foreman/blob/wip\_plugins/vars/Ubuntu.yml](https://github.com/kostyrevaa/ansible-role-foreman/blob/wip_plugins/vars/Ubuntu.yml)  
and for RHEL  
[https://github.com/kostyrevaa/ansible-role-foreman/blob/wip\_plugins/vars/RedHat\_7.yml](https://github.com/kostyrevaa/ansible-role-foreman/blob/wip_plugins/vars/RedHat_7.yml)

those vars are pulled with  
[https://github.com/kostyrevaa/ansible-role-foreman/blob/wip\_plugins/tasks/main.yml#L4](https://github.com/kostyrevaa/ansible-role-foreman/blob/wip_plugins/tasks/main.yml#L4)

and code that installs those plugins:  
[https://github.com/kostyrevaa/ansible-role-foreman/blob/wip\_plugins/tasks/plugins.yml#L21](https://github.com/kostyrevaa/ansible-role-foreman/blob/wip_plugins/tasks/plugins.yml#L21)

Of course it’s not gonna work for ubuntu 'cause I don’t render repo files for it  
but  
it also fails for rhel with aforementioned error.

Is there any workaround I could use to get what I want?

Thanks!

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.ansible.com/u/user66)\
**Post date:** [December 7, 2015, 10:42pm UTC](https://forum.ansible.com/t/yum-module-fails-to-install-multiple-packages/19951/5 "2015-12-07T22:42:32Z")

</div>

I don’t know which plugins someone would like to install so I can’t have hard-coded list.

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.ansible.com/u/user66)\
**Post date:** [December 7, 2015, 11:06pm UTC](https://forum.ansible.com/t/yum-module-fails-to-install-multiple-packages/19951/6 "2015-12-07T23:06:00Z")

</div>

and I’d like to add that end-user should not be bothered with differences in packages’ names in OSes  
Setting

foreman\_plugins:

- discovery
- bootdisk

is all what have to be done.

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.ansible.com/u/user66)\
**Post date:** [December 8, 2015, 1:42pm UTC](https://forum.ansible.com/t/yum-module-fails-to-install-multiple-packages/19951/7 "2015-12-08T13:42:55Z")

</div>

Strangely enough but after rewriting

`

- name: install plugins  
yum: name=‘ruby193-rubygem-{{ item }}’ state=present

`

into

- name: install plugins OS agnostic  
action: \>  
{{ ansible\_pkg\_mgr }}  
name=“{{ foreman\_plugin\_prefix }}{{ item }}”

it works! so my problem solved
