onknows
onknows

Reputation: 6691

Does Ansibe support Python 3? If you require Python 3 support use the `dnf` Ansible module instead

When I configure python3 for target node for example as follows

ansible_python_interpreter=/usr/bin/python3

This results in an error message on tasks that use package module.

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

This make me wonder if Ansible supports Python 3 on target nodes. On my controller node I have Ansible 2.10.3 / Python 3.6.9 which seems to work fine. But on the target node the very very common package module is no longer usable and needs to be replace with dnf module.

The problem is that thousands of Ansible roles published on Ansible Galaxy use the package module.

The conclusion is that Ansible 2.10.3 does not support Python 3 in practice?

Wouldn't it be better to change the package module to support dnf? That way we wouldn't have to change all the Ansible roles for Python 3. Ansible Galaxy roles ideally would not have to be changed to support a different version of Python. If at all possible.

In any case, what is the recommend practice currently? Don't use Python 3 on target nodes?

Upvotes: 2

Views: 5191

Answers (1)

Zeitounator
Zeitounator

Reputation: 44635

TL;DR: Ansible supports python 3 on both controller and target but not all of its modules. yum is one of those.


From the package module documentation:

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

So unless you override the package manager you want to run with the use parameter, package will run the yum module for operating systems using it.

From the yum module documentation

This module only works on Python 2

So for those systems, you will need to use python 2 on the target when running the package module. And chances are this is the case when using interpreter discovery

For systems (e.g. more recent rhel/centos os) using dnf, package will run the corresponding module with any version of python >= 2.6

Upvotes: 2

Related Questions