skip to Main Content

I have followed things suggested in different resources.. most of them suggests mentioned here ansible yum not working

- name: Update a package with the latest version
    yum:
      name: package_name
      enablerepo: enable_required_repo 
      state: latest

I get following error

fatal: [hostname]: FAILED! => {"changed": false, "msg": "The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.. The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead."}

ansible 2.8.4
 config file = /etc/ansible/ansible.cfg
 configured module search path = [u'/usr/share/ansible']
 ansible python module location = /usr/lib/python2.7/site-packages/ansible
 executable location = /usr/bin/ansible
 python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

running command ansible hosts -m raw -b -a "yum -y update package" separately works

Am I missing something?

2

Answers


  1. Running a raw command invoking yum directly is not the same as the yum module in ansible. The former simply uses standard command invocation mechanisms to execute yum, notably without deep insight into intended result and thus lacking idempotency (ansible doesn’t know from that whether action is changed/ok). But the latter is totally different. It’s implemented in ansible as python that is assembled and shipped to the remote client as an executable blob.

    python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

    Remember, even though python on the controlling host cooked up the python it sent to the target host, that doesn’t necessarily mean the interpreter is the same. In your case the controller may well have ansisble + py 2.7 but that doesn’t mean the failing host has py2.7 on its end by default.
    Ansible has not uncommonly seen the problem in the past that the wrong interpreter gets picked up for whatever reason; in this case you can set ansible_python_interpreter on a per host/group/other scope basis to the right python.

    The good news is it looks like you can probably just switch over to the dnf module: https://docs.ansible.com/ansible/latest/modules/dnf_module.html. Give it a try, as python 3 is just something we’re all going to have to work through at this point.

    Login or Signup to reply.
  2. what happens if you manually set the python interpreter to be python2? E.g.

    ansible-playbook your-play-book.yml -e 'ansible_python_interpreter=/path/to/your/python2'
    

    Could be that despite the configuration of
    python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
    python3 is being used

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search