0

I am trying to use Ansible 2.7.7 to manage Ubuntu 16.04 cloud image but when I try to make connection I get error:

SSH Error: data could not be sent to remote host "192.168.111.11". Make sure this host can be reached over ssh

If I issue command ssh ubuntu@192.168.111.11 on the Ansible host I can connect to target server without problems. I can also sudo there without password prompt.

If look at logs of the target machine I see that Ansible successfully logged in to the machine:

Feb 20 11:44:51 ubuntu sshd[2870]: Accepted publickey for ubuntu from 192.168.111.111 port 56236 ssh2: RSA SHA256:yI...
Feb 20 11:44:51 ubuntu sshd[2870]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)
Feb 20 11:44:51 ubuntu systemd-logind[1090]: New session 13 of user ubuntu.
Feb 20 11:44:51 ubuntu sudo:   ubuntu : TTY=unknown ; PWD=/home/ubuntu ; USER=root ; COMMAND=/bin/sh -c echo BECOME-SUCCESS-kldfjkldjhjljkl; /usr/bin/python
Feb 20 11:44:51 ubuntu sudo: pam_unix(sudo:session): session opened for user root by (uid=0)
Feb 20 11:44:51 ubuntu sudo: pam_unix(sudo:session): session closed for user root

Verbose output:

ansible-playbook -i inventory default.yaml -vvv
ansible-playbook 2.7.7
  config file = /home/admin/ansible/ansible.cfg
  configured module search path = [u'/home/admin/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/admin/ansible/ansible-env/local/lib/python2.7/site-packages/ansible
  executable location = /home/admin/ansible/ansible-env/bin/ansible-playbook
  python version = 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
Using /home/admin/ansible/ansible.cfg as config file
/home/admin/ansible/inventory did not meet host_list requirements, check plugin documentation if this is unexpected
/home/admin/ansible/inventory did not meet script requirements, check plugin documentation if this is unexpected
Parsed /home/admin/ansible/inventory inventory source with ini plugin

PLAYBOOK: default.yaml *******************************************************************************************************************************************************************************************************************
1 plays in default.yaml

PLAY [default] ***************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************************
task path: /home/admin/ansible/default.yaml:3
Using module file /home/admin/ansible/ansible-env/local/lib/python2.7/site-packages/ansible/modules/system/setup.py
<192.168.111.11> ESTABLISH SSH CONNECTION FOR USER: ubuntu
<192.168.111.11> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 -o ControlPath=/home/admin/.ansible/cp/a9e60c69b0 192.168.111.11 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-tenlfcstwmojszikegdyatixrzpwqwah; /usr/bin/python'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
fatal: [192.168.111.11]: UNREACHABLE! => {
    "changed": false,
    "unreachable": true
}

MSG:

SSH Error: data could not be sent to remote host "192.168.111.11". Make sure this host can be reached over ssh

What could be causing this issue?

  • 1
    Try with pipelining disabled or without become. If that's the case inspect sudo and terminal configuration on the remote system. – Konstantin Suvorov Feb 20 at 12:08
  • @KonstantinSuvorov Thanks, disabling pipelining solved the problem. – Madoc Comadrin Feb 20 at 12:54
  • 1
    It helped you to narrow the number of possible reasons, but in no way solved the real problem... – Konstantin Suvorov Feb 20 at 13:00
  • @KonstantinSuvorov Wrong, it solved the problem completely. – Madoc Comadrin Feb 20 at 13:57
  • Run the actual ssh command yourself, which appears after SSH: EXEC to see the results. This will give you the error that may not be otherwise visible. – Michael Hampton Feb 20 at 16:06
0

Turns out my target system required tty when using sudo.

I was able to make connection my commenting out this line from ansible.cfg:

pipelining = True

Other option would have been disabling setting requiretty from sudoer file.

  • Remember that this is a workaround. You still have a lingering problem that remains unsolved and will probably come back to bite you in some unexpected way in the future. – Michael Hampton Feb 22 at 14:47

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.