我遵循了不同资源中建议的内容.. 其中大多数建议在这里提到 ansible yum not working
- name: Update a package with the latest version
yum:
name: package_name
enablerepo: enable_required_repo
state: latest
我收到以下错误
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)]
运行命令
ansible hosts -m raw -b -a "yum -y update package"
分开工作我错过了什么吗?
最佳答案
运行调用 yum
的原始命令直接与yum
不一样ansible 中的模块。前者简单地使用标准的命令调用机制来执行yum
,特别是没有深入了解预期结果,因此缺乏幂等性(ansible 不知道 Action 是否改变/正常)。但后者完全不同。它在 ansible 中实现为 python,它被组装并作为可执行 blob 发送到远程客户端。
python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
请记住,即使控制主机上的 python 制作了它发送到目标主机的 python,这并不一定意味着解释器是相同的。在您的情况下, Controller 很可能具有 ansble + py 2.7 但这并不意味着故障主机默认情况下具有 py2.7。
Ansible 过去并不少见,无论出于何种原因选择了错误的解释器。在这种情况下,您可以设置
ansible_python_interpreter
在每个主机/组/其他范围的基础上到正确的 python。好消息是您似乎可以切换到
dnf
模块:https://docs.ansible.com/ansible/latest/modules/dnf_module.html .试一试,因为 python 3 只是我们现在必须完成的工作。
关于python - 在多个主机上通过 Ansible 运行 yum update 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58617202/