Ansible’s yum-module and yum itself

Today I had a problem with some RPMs which are replacing each other. Assume you have a package A which is providing X and a package B which is providing X, too. Then assume you have an application package which requires until a certain version package A and higher versions then package B. On top of this there are also the dependencies not described very well in the specfile of the application package itself.

So what is ansible doing in such a case?

Well, when you have now a playbook which let you choose which version you want to install and you need to clean up package A or package B (depending which version you choose) the you do probably something like this:

- name: "install version 1.0"
  become: true
  yum:
    name="application-package-1.0"
    state="present"
  when: some-magic-variable-is-set

So now what is happening? Yum sees that the application-package needs package X and picks just the latest version of the package X (as A and B are providing X).

The same happens actually also with the state=”absent”.

- name: "Remove package A before installing application-package"
  become: true
  yum:
    name="A"
    state="absent"

Now when package B is installed and should not be removed yum is removing it in anyway. It sees that there is a package which provides X and as the package A also provides X, then the assumption is taken, that the user wants actually remove package A.

So my solution was to query the rpm-DB before calling the removal of the package:

  - name: "Check if package A is really installed"
    shell: rpm -qa | grep real-name-of-package-A
    changed_when: no
    ignore_errors: true
    register: A_IS_INSTALLED

- name: "Remove package A before installing application-package"
  become: true
  yum:
    name="A"
    state="absent"
  when: A_IS_INSTALLED.rc == 0 and some-magic-variable-is-set

Hopefully this was clear what I have written here, it’s already late and had to fight a lot today with ansible… :-D

Leave a Reply