Introduction Ansible requires Python on managed nodes to execute most modules. When Python or required modules are missing, tasks fail with "module not found" or "interpreter not found" errors.

Symptoms - "Failed to find required interpreter python3" - "module not found" for specific Python modules - "No package matching 'python3' is available" - Tasks fail immediately with MODULE FAILURE - Works on some hosts but not others

Common Causes - Python not installed on minimal OS images (Alpine, Container Linux) - Python3 not found but Python2 exists (or vice versa) - Required Python packages not installed (e.g., apt, yum, docker) - Virtual environment not activated for Ansible - OS distribution change without updating ansible_python_interpreter

Step-by-Step Fix 1. **Check Python availability on target**: ```bash ansible <target> -m raw -a "which python3 || which python" ansible <target> -m raw -a "python3 --version" ```

  1. 1.Set the correct Python interpreter in inventory:
  2. 2.```ini
  3. 3.[all:vars]
  4. 4.ansible_python_interpreter=/usr/bin/python3
  5. 5.`
  6. 6.Install Python before running other tasks:
  7. 7.```yaml
  8. 8.- hosts: all
  9. 9.gather_facts: no
  10. 10.tasks:
  11. 11.- name: Install Python
  12. 12.raw: test -e /usr/bin/python3 || (apt update && apt install -y python3)
  13. 13.- name: Gather facts
  14. 14.setup:
  15. 15.`
  16. 16.Use ansible.builtin.raw module for bootstrapping:
  17. 17.```bash
  18. 18.ansible <target> -m raw -a "apt update && apt install -y python3"
  19. 19.`

Prevention - Always include Python installation in base image provisioning - Use gather_facts: no and raw module for initial setup - Pin ansible_python_interpreter in inventory for consistency - Test playbooks against minimal OS images - Use ansible-lint to catch interpreter issues