During a playbook run I was presented with the following error:
failed: [localhost] (item=[u'yum']) => {"failed": true, "item": ["yum"], "msg": "python2 yum module is needed for this module"}
The role that was executing had a task similar to the following:
- name: Install rsyslog packages
yum: pkg={{item}} state=installed update_cache=false
with_items:
- rsyslog
notify: Restart rsyslog service
The OS on the system I was trying to update was running Fedora 26 which uses the dnf package manager. Dnf is built on top of Python3 and Fedora 26 no longer includes the yum Python 2 bindings by default (if you want to use the ansible yum module you can create a task to install the yum package). Switching the task to use package instead of yum remedied this issue. Here is the updated task:
- name: Install rsyslog packages
package: pkg={{item}} state=installed
with_items:
- rsyslog
notify: Restart rsyslog service
The issue was easy to recognize after reading through the yum module source code. Posting this here in case it helps others.