SSH确定但Ansible返回"无法访问"

时间:2016-11-15 10:39:26

标签: ssh ansible ansible-playbook

我的SSH使用密钥设置正确。

ssh admin@192.168.1.111
admin@DiskStation:~$

但Ansible返回错误:

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}

有人可以帮助我吗?

4 个答案:

答案 0 :(得分:2)

Ansible返回&#34;无法访问&#34;对于SFTP连接,而不是SSH。

在目标节点(或中间的防火墙)上启用SFTP,或在ansible.cfg中将Ansible配置为use SCP

scp_if_ssh = True

答案 1 :(得分:2)

我有类似的&#34;无法到达&#34;错误,但在我的情况下,这是因为我的playbook文件以这种方式指定了主机:

[webservers]
ubuntu@123.456.789.111

这在过去对我们有用,所以可能这适用于一些Ansible版本,但不适用于我的版本(2.0.0.2)。相反,我将其更改为文档建议的内容:

[webservers]
123.456.789.111 ansible_user=ubuntu

现在SFTP连接不会失败。

答案 2 :(得分:0)

请检查目标计算机上是否安装了python。这是先决条件。

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

答案 3 :(得分:0)

经过多年的尝试和错误,现在我的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
  • pipelining是我个人在处理多个 主机。
  • ssh_args处理挂起和超时,这在目标遥控器的连接不稳定时很有用。