ansible yum not working
Asked Answered
M

3

8

when i run command on the ops machine:

ansible web -b -l 192.168.31.101 -m yum -a "name=gcc state=latest"

it returns error shows below:

192.168.31.101 | FAILED! => {
    "changed": false,
    "failed": true,
    "msg": "python2 bindings for rpm are needed for this module. python2 yum module is needed for this  module" 
}

but when i execute the command sudo yum install gcc directly on 192.168.31.101, executed properly.

it seems like ansible can't use the right yum and python

Mortar answered 2/11, 2017 at 7:5 Comment(1)
Try using -m package instead of -m yum. It's supposed to work with various package managers. I think yum is going to get replaced by DNF. en.wikipedia.org/wiki/Dnf_(Fedora). Perhaps the yum python module is no longer installed by default in the latest centos images?Denham
M
8

I find the solution, just add a python path to hosts file

ansible_python_interpreter=/usr/bin/python2.7
Mortar answered 3/11, 2017 at 8:8 Comment(0)
W
0

this happened to me because i had python2.7 and python3 installed on my machin. ansible was using python3 and thus the error. so I had to explicitly specify it like below in my makefile target /bin/python2.7 /bin/ansible-playbook configure-box.yml

Weatherwise answered 21/2, 2018 at 9:25 Comment(0)
W
0

In my condition, I need install yum package and reconfig virtualenv with flag --system-site-packages on target host, then use ansible environment variable ansible_python_interpreter.

yum install yum
virtualenv --system-site-packages venv
Willey answered 8/1, 2020 at 9:24 Comment(1)
You probably mean pip install yum ?Downcast

© 2022 - 2024 — McMap. All rights reserved.