I just started learning the basics of Ansible. And facing some problem related to server connectivity via SSH. I created a folder named publich_html and put my code into that folder and changed the permission. When I try to execute my playbook it gives me the following error

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"

Whereas when I try to ping servers from user home or root user without going into a directory it pings perfectly. Here is the verbose output :

SSH: EXEC sshpass -d15 sftp -b - -C -vvv -o ForwardAgent=yes -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10

config file is:

host_key_checking = False

I don't know where I am missing something. Anyone have any idea about it?

  • With ping do you mean the regular unix command, or something in ansible? What does ansible hostname -m raw -a id show? I don't understand why you're mentioning the public_html (or is it really publich_html?).
    – wurtel
    May 19 '16 at 14:39
  • with ping i meant ansible ping command. ans I am mentoning the public_html folder just because i simply created a directory with this name and put my playbook and role in it. May 20 '16 at 7:20

I recently resolved a similar issue, where Ansible would encounter "UNREACHABLE!" errors only for tasks requiring file transfers (e.g. copy, template) while connecting just fine for anything else. I resolved it by adding the following directive to ansible.cfg, under the [ssh_connection] section:

scp_if_ssh = True

As you might guess from that fix, the issue was related to the target servers' SFTP configuration. Since Ansible uses SFTP by default to transfer files, the misconfigured servers encountered errors for any Ansible tasks that involved file transfers. So, if this change makes the errors go away, I recommend checking your target servers' sshd_config files for errors in the SFTP configuration.

  • That's really awesome. And it will definitely help May 27 '16 at 4:32

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.