module_stderr: Shared connection to IP closed

I have received the below error when I am executing ansible command. I am adding this error and the fix so it may help other.

The Ansible is installed on Centos machine and executing command on remote Ubuntu machine and got below error message.

ERROR:-

[root@localhost ~]# ansible -i ansible-proj/inventory all -m ping

172.30.41.115 | FAILED! => {

    "changed": false, 

    "module_stderr": "Shared connection to 172.30.41.115 closed.\r\n", 

    "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", 

    "msg": "MODULE FAILURE", 

    "rc": 0

}

 

REASON:-

The above error is coming because by default the Ubuntu 18 does not have python2. To overcome this issue install python2 on the remote machine or add python3 path in the Ansible inventory file.

 

FIX

To fix this issue am adding the python3 path in my inventory file (ansible-proj/inventory).

 

[root@localhost ~]# cat ansible-proj/inventory 

[all]

172.30.41.115 ansible_python_interpreter=/usr/bin/python3

 

Here I have added python3 path in inventory file. Now execute the Ansible command to confirm it is working.

 

[root@localhost ~]# ansible -i ansible-proj/inventory all -m ping

172.30.41.115 | SUCCESS => {

    "changed": false, 

    "ping": "pong"

}

 

 

Yes this time the “ping” command worked successfully 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *