百胜百胜不工作

ansible yum not working

当我在 ops 机器上 运行 命令时:

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

它returns错误如下所示:

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" 
}

但是当我直接在 192.168.31.101 上执行命令 sudo yum install gcc 时,执行正确。

ansible 好像不能使用正确的 yum 和 python

我找到了解决方案,只需添加 python hosts 文件的路径

ansible_python_interpreter=/usr/bin/python2.7

这件事发生在我身上是因为我的机器上安装了 python2.7 和 python3。 ansible 正在使用 python3 ,因此出现了错误。 所以我必须像下面这样在我的 makefile 目标中明确指定它 /bin/python2.7 /bin/ansible-playbook configure-box.yml

在我的情况下,我需要在目标主机上安装 yum 软件包并使用标志 --system-site-packages 重新配置 virtualenv,然后使用 ansible 环境变量 ansible_python_interpreter.

yum install yum
virtualenv --system-site-packages venv