python - 在多个主机上通过 Ansible 运行 yum update 不工作

标签 python ansible centos yum

我遵循了不同资源中建议的内容.. 其中大多数建议在这里提到 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/

相关文章:

ansible - 列出任务 list 文件中的所有 ansible 主机

PHP 参数选项错误未找到 r

python - 如何只记录某个级别名称的python日志记录

python - 通过套接字从 C++ 服务器向 Python 客户端发送数据时出现问题

windows - Ansible:无法在 Windows 节点上执行 ping [SSL:CERTIFICATE_VERIFY_FAILED]

linux - 将输出存储到 shell 变量中

centos - 警告 : Authentication failure. 正在重试

python - 将来自多个小部件的相同信号连接到 PyQt 中的同一函数?

python - SQLAlchemy:使用 id 而不是对象添加关系?

powershell - Ansible Playbook - 从 Windows 远程机器获取文件