Tag Archives: yum

Ansible: yum with_items gotcha

There are a few issues raised on https://github.com/ansible/ansible/issues concerning a bug in which Ansible 2.1 reports a task to be OK when it in fact fails, although Ansible stops and the summary output reports a failed task. This is reproducible when using the yum module with a with-loop that lists RPMs for installation as shown in the example below.

vars:
 packages: ['binutils','compat-libstdc++-33','elfutils-libelf','elfutils-libelf-devel','expat','gcc','gcc-c++','glibc','glibc-common','glibc-devel','glibc-headers','libaio','libaio-devel','libgcc','libstdc++','libstdc++-devel','make','sysstat','unixODBC','unixODBC-devel','kmod-oracleasm','openssh-clients','compat-libcap1','compat-libstdc++-33']

tasks:
- name: Installing oracle required RPMs..
 yum:
 name: "{{ item }}"
 state: present
 with_items:
 - "{{ packages }}"

I stumbled across this gotcha when installing Oracle 12c Grid Infrastructure and couldn’t understand why my playbook stopped when the task execution seemingly succeeded.

I discovered the root cause by substituting a shell command to call yum.

- name: Installing oracle required RPMs..
 shell: yum install "{{ item }}"
 with_items:
 - "{{ packages }}"

Despite the “[WARNING]: Consider using yum module rather than running yum“, I found that a few packages in the long list of Oracle required RPMs, did not exist in the local yum repository!

The workaround

Removing the “bad” RPMS from the list, enabled the task to succeed when using the yum with_items.

The solution

Details of the permanent fix can be found here:
https://github.com/ansible/ansible/commit/20726b94be64b17829f5afb712b4b5f542515229

[contact-form][contact-field label=’Name’ type=’name’ required=’1’/][contact-field label=’Email’ type=’email’ required=’1’/][contact-field label=’Website’ type=’url’/][contact-field label=’Comment’ type=’textarea’ required=’1’/][/contact-form]