大网数据广告活动
服务器运维问答

Ansible - SSH Error: data could not be sent to remote host

· 52CE 我爱测

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 …

问题原文

原帖链接 · Madoc Comadrin · CC BY-SA 4.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 [email omitted] 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?

已采纳解答

原帖链接 · Madoc Comadrin · CC BY-SA 4.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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-02-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。