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?
Yes, the
raw
module is the preferred way to install Python with Ansible. You might want to include some other necessary packages for Ansible as well:easy_install
depends on Python. There is no way aroundraw
when Python is not present. Usually I use thisraw
task as part of a special bootstrapping playbook executed only once. Another reason to define this task outside the other roles and plays is that you cannot use fact gathering when Python is not present on the target system.