I am using ansible to try and set up a server. At the moment the server has a root user who authenticates with a password (no ssh key required). If I ssh manually from my command line I am prompted for the password and log in no problem.

This is what I'm seeing when I try and use ansible:

python3 $(which ansible) our.server.net -m ping -c ssh --ask-pass -u root
SSH password: 
our.server.net | UNREACHABLE! => {
    "changed": false,
    "msg": "SSH Error: data could not be sent to remote host \"\". Make sure this host can be reached over ssh",
    "unreachable": true

If I add -vvvv I get a bit more info (just including the important bit here)

Loading callback plugin minimal of type stdout, v2.0 from /usr/local/lib/python3.6/site-packages/ansible/plugins/callback/minimal.py
META: ran handlers
Using module file /usr/local/lib/python3.6/site-packages/ansible/modules/system/ping.py
<> SSH: EXEC sshpass -d9 ssh -vvv -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey -o ForwardAgent=yes -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/home/martinw/.ansible/cp/eeb0630cdf '/bin/sh -c '"'"'/usr/bin/python && sleep 0'"'"''our.server.net | UNREACHABLE! => {
    "changed": false,
    "msg": "SSH Error: data could not be sent to remote host \"\". Make sure this host can be reached over ssh",
    "unreachable": true

Is there something I'm missing in my environment / ansible settings here?


I believe Jeff Geerling, has answered this problem.



It's easy enough to work around this problem, though! If you have the ability to build your own base images (e.g. AMIs on AWS), you can just make sure /usr/bin/python is already installed on the image. And if only python3 is present, you can set ansible_python_interpreter=/usr/bin/python3 in your inventory for the affected hosts. If you can't do either of these things, the best

Or install working python version.

- hosts: all
  gather_facts: no

    - name: Install Python if not already present.
      raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
      changed_when: False

    - name: Gather facts after Python is definitely present.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.