Sobes.tech
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:

  1. 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"
  1. Use the ansible_python_interpreter parameter to specify an alternative interpreter if available.

  2. In newer versions of Ansible, it is possible to use "Python-less" management with ansible-pull or 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.