Paul
Paul

Reputation: 1390

SSH ok but Ansible returns "unreachable"

My SSH using keys is set up properly.

ssh [email protected]
admin@DiskStation:~$

But Ansible returns an error:

TASK [setup] *******************************************************************
<192.168.1.111> ESTABLISH SSH CONNECTION FOR USER: admin
<192.168.1.111> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=admin -o ConnectTimeout=10 -o ControlPath=/Users/Shared/Jenkins/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.1.111 '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1479205446.3-33100049148171 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1479205446.3-33100049148171 `" )'"'"''
<192.168.1.111> PUT /var/folders/pd/8q63k3z93nx_78dggb9ltm4c00007x/T/tmpNJvc43 TO /var/services/homes/admin/.ansible/tmp/ansible-tmp-1479205446.3-33100049148171/setup
<192.168.1.111> SSH: EXEC sftp -b - -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=admin -o ConnectTimeout=10 -o ControlPath=/Users/Shared/Jenkins/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.1.111]'
fatal: [192.168.1.111]: UNREACHABLE! => {"changed": false, "msg": "SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}

Can someone help me?

Upvotes: 8

Views: 17834

Answers (5)

Tebe
Tebe

Reputation: 3214

Give a try:

ansible-playbook -c paramiko

It falls back to python based ssh authorisation. Helped in my case

Upvotes: 0

eduprado
eduprado

Reputation: 81

After many years of try and error, now I always have these setting on my ansible.cfg:

[defaults]
host_key_checking = false

[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o ServerAliveInterval=20
scp_if_ssh = True

[connection]
pipelining = true
  • The pipelining is my personal preference when dealing with multiple hosts.
  • The ssh_args deals with hangs and timeouts, useful when your target remote has unstable connection.

Upvotes: 1

Shantanu Jain
Shantanu Jain

Reputation: 3

Please check if python is installed on the target machines. It's a prerequisite.

sudo apt install python3
sudo apt install python
sudo apt install python-minimal

Upvotes: 0

Dan Stowell
Dan Stowell

Reputation: 4758

I had a similar "unreachable" error, but in my case it was because my playbook file specified the host this way:

[webservers]
[email protected]

This worked for us in the past, so presumably this works with some Ansible versions, but not with my version (2.0.0.2). Instead I changed this to what the documentation recommends:

[webservers]
123.456.789.111 ansible_user=ubuntu

and now the SFTP connection does not fail.

Upvotes: 2

techraf
techraf

Reputation: 68439

Ansible returns "unreachable" for the SFTP connection, not SSH.

Either enable SFTP on the target node (or a firewall in-between), or configure Ansible to use SCP in ansible.cfg:

scp_if_ssh = True

Upvotes: 4

Related Questions