Senior
Is it possible to install Python on a host where Python is not installed yet using Ansible?
sobes.tech AI
Answer from AI
Ansible by default uses Python on the target host to execute modules. If Python is not installed, standard modules will not work. However, there are several ways to work around this:
- Use the Ansible raw module, which sends and executes commands directly via SSH without requiring Python. You can install Python using a package manager, for example:
- name: Install Python on a host without Python
hosts: all
tasks:
- name: Install Python via raw
raw: yum install -y python3
when: ansible_os_family == "RedHat"
-
Use the
ansible_python_interpreterparameter to specify an alternative interpreter if available. -
In newer versions of Ansible, it is possible to use "Python-less" management with
ansible-pullor other methods, but this requires additional configuration.
Thus, it is not possible to do this directly through standard modules without Python, but it can be solved via the raw module or pre-installation.