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
Ansible's yum module is used to manage packages with the yum package manager, which is the default on Red Hat based Linux distributions such as Red Hat Enterprise Linux and CentOS. Most systems require root/superuser permissions to manage packages, which means that become: true is required.
This module is part of ansible-core and included in all Ansible installations. In most cases, you can use the short module name yum_repository even without specifying the collections: keyword.
Package installation is a relatively simple task and only requires two elements. The state option instructs Ansible to check whether or not some package is present on the system, and the name option lists which packages to look for. Ansible deals in machine state, so module instructions always imply change.
I find the solution, just add a python path to hosts file
ansible_python_interpreter=/usr/bin/python2.7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With