I'm not able to connect to a host in Ansible. This is the error: | UNREACHABLE! => { "changed": false, "msg": "ERROR! SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue", "unreachable": true }

This is my hosts file:


And this is the ad-hoc instruction:

ansible all -m ping

I'm able to connect via raw ssh


The error it returns says it all, the host is unreachable as ssh doesn't work. See what the ping command does in ansible:

ping - Try to connect to host, verify a usable python and return pong on success.

If you can do raw ssh, doesn't ensure ansible can. You need to setup key based ssh or add passowrd option:

ansible all -m ping --ask-pass

When speaking with remote machines, Ansible by default assumes you are using SSH keys. SSH keys are encouraged but password authentication can also be used where needed by supplying the option --ask-pass. If using sudo features and when sudo requires a password, also supply --ask-sudo-pass.

Ref: http://docs.ansible.com/ansible/intro_getting_started.html

| improve this answer | |
  • Thank you. I have used --ask-pass and --ask-sudo-pass and it worked – Héctor Jan 18 '16 at 14:23

Solved by removing ansible_become=true in the /etc/ansible/hosts file.

| improve this answer | |
  • 2
    This is hardly a "solution". If you need become for your tasks, configure the machines properly so that it works. – Gerald Schneider Dec 12 '18 at 10:05

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.