Getting the ansible yum module to work on Fedora servers


I was doing some testing this morning on a Fedora 25 host and received the following error when I tried to execute a playbook:

$ ansible-playbook --ask-become-pass -l tbone playbooks/system-base.yml

PLAY [all] ********************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************
ok: [tbone]

TASK [system-common : upgrade all packages] ***********************************************************************
fatal: [tbone]: FAILED! => {"changed": false, "failed": true, "msg": "python2 yum module is needed for this  module"}
	to retry, use: --limit @/ansible/playbooks/system-base.retry

PLAY RECAP ********************************************************************************************************
tbone        : ok=1    changed=0    unreachable=0    failed=1

To see what ansible was doing I set the ANSIBLE_KEEP_REMOTE_FILES environment variable which keeps the ansiballz modules on the remote host (this is super useful for debugging problems). After reviewing the files in the temporary task directory I noticed that the playbook had a task to install a specific version of a package with yum. Yum doesn’t exist on newer Fedora releases hence the “python2 yum module” error.

There are a couple of ways to fix this. The ideal way is to use the package module (or check the OS release and use the ansible dnf module instead of yum) instead of specifying yum or dnf. If you need a quick fix you can shell out from your playbook and install python2-dnf prior to gathering facts. If you need a quicker fix you can install the package by hand:

$ yum -y install python2-dnf

I’m currently using the package module and it works like a champ.

This article was posted by Matty on 2017-09-07 13:44:00 -0400 -0400