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