Ansibe支持Python 3吗?如果需要Python3支持,请改用`dnf`Ansible模块

2024-04-19 22:48:03 发布

您现在位置:Python中文网/ 问答频道 /正文

例如,当我为目标节点配置python3时,如下所示

ansible_python_interpreter=/usr/bin/python3

这会导致使用package模块的任务出现错误消息

The Python 2 bindings for rpm are needed for this module. If you require Python 3 support use the dnf Ansible module instead

这让我怀疑Ansible是否在目标节点上支持Python 3。在我的控制器节点上,我有Ansible 2.10.3/Python 3.6.9,它似乎工作得很好。但是在目标节点上,非常常见的package模块不再可用,需要用dnf模块替换

问题在于,Ansible Galaxy上发布的数千个Ansible角色都使用了package模块

结论是Ansible 2.10.3实际上不支持Python 3

package模块更改为支持dnf不是更好吗?这样我们就不必更改Python3的所有Ansible角色。Ansible Galaxy角色理想情况下不必更改以支持不同版本的Python。如果可能的话

在任何情况下,目前推荐的做法是什么?不要在目标节点上使用Python 3


Tags: 模块角色package目标for节点usr情况
1条回答
网友
1楼 · 发布于 2024-04-19 22:48:03

TL;DR:ansible在控制器和目标上都支持python 3,但不是它的所有模块yum就是其中之一


^{} module documentation开始:

This module actually calls the pertinent package modules for each system (apt, yum, etc).

因此,除非重写要使用^{} parameter运行的包管理器,否则package将为使用它的操作系统运行yum模块

^{} module documentation

This module only works on Python 2

因此,对于这些系统,在运行package模块时,需要在目标上使用python 2。使用interpreter discovery时很可能就是这种情况

对于使用dnf的系统(例如,较新的rhel/centos os),将使用任何版本的python运行corresponding module2.6

相关问题 更多 >