1

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 \"10.123.80.75\". 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
<10.123.80.75> ESTABLISH SSH CONNECTION FOR USER: root
<10.123.80.75> 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 10.123.80.75 '/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 \"10.123.80.75\". Make sure this host can be reached over ssh",
    "unreachable": true
}

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

0

I believe Jeff Geerling, has answered this problem.

https://www.jeffgeerling.com/blog/2018/fixing-unreachable-ssh-error-when-running-ansible-playbooks-against-ubuntu-1804-or-1604

https://www.jeffgeerling.com/blog/2017/how-fix-ssh-errors-when-using-ansible-newer-oses-ubuntu-1604

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

  pre_tasks:
    - 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.
      setup:
| 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.