'What is the prefered method to install Python with Ansible on CentOS 8
CentOS 8 does not always come with Python pre-installed, and so Ansible will fail running on the remote machine until it's been installed. However in a classic Chicken/Egg, you can't use the Ansible dnf module to install Python.
I've been using:
- name: Install Python 3
raw: dnf -y install python3
However the problem with this is that I either have to set changed_when: false or it will always return a changed state. I'd like the state reported properly if it's possible.
I found easy_install however this appears to only deal with Python Libraries, and not Python itself. Is there a built-in way to handle this or is raw: the only option?
Solution 1:[1]
As it goes, there is no simple answer, the truth is that if Python is not installed, the only method to get it installed with Ansible is to use the raw: method. Here is the answer I was provided at ServerFault... https://serverfault.com/questions/1016870/what-is-the-prefered-method-to-install-python-with-ansible-on-centos-8
Solution 2:[2]
This is incorrect. CentOS 8 comes with platform-python out of the box, which Ansible >= 2.8 will use by default.
https://developers.redhat.com/blog/2018/11/14/python-in-rhel-8-3
https://www.ansible.com/blog/integrating-ansible-and-red-hat-enterprise-linux-8-beta
https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html
Happy automating!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | oucil |
| Solution 2 | rmbrad |
