Running ansible modules remotely requires python being installed in the remote system.
To show this we need to have a simple inventory with all the hosts:
root@f12d33c83ada:~# cat inventory.yaml
all:
hosts:
172.17.0.3:
172.17.0.4:
Trying to use ping get us:
root@f12d33c83ada:~# ansible all -i inventory.yaml -m ping
[WARNING]: No python interpreters found for host 172.17.0.4 (tried ['python3.10', 'python3.9', 'python3.8', 'python3.7', 'python3.6',
'python3.5', '/usr/bin/python3', '/usr/libexec/platform-python', 'python2.7', 'python2.6', '/usr/bin/python', 'python'])
172.17.0.4 | FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"module_stderr": "Shared connection to 172.17.0.4 closed.\r\n",
"module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n",
"msg": "The module failed to execute correctly, you probably need to set the interpreter.\nSee stdout/stderr for the exact error",
"rc": 127
}
[...]
You can use the raw
module to install python in the remote host:
root@f12d33c83ada:~# ansible all -i inventory.yaml -m raw -a "apt update && apt install -y python3-minimal"
172.17.0.3 | CHANGED | rc=0 >>
[...]
Processing triggers for libc-bin (2.31-13+deb11u2) ...
Shared connection to 172.17.0.3 closed.
172.17.0.4 | CHANGED | rc=0 >>
Hit:1 http://security.debian.org/debian-security bullseye-security InRelease
Hit:2 http://deb.debian.org/debian bullseye InRelease
[...]
Once python is installed, ansible will find the interpreter:
root@f12d33c83ada:~# ansible all -i inventory.yaml -m ping
172.17.0.3 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}
172.17.0.4 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"ping": "pong"
}