ansible SSH 连接失败 [英] ansible SSH connection fail
问题描述
我正在尝试在多台服务器上运行 ansible 角色,但出现错误:
I'm trying to run ansible role on multiple servers, but i get an error:
致命:[192.168.0.10]:无法访问!=> {改变":假,味精":"无法通过 ssh 连接到主机.", "unreachable": true}
fatal: [192.168.0.10]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
我的/etc/ansible/hosts 文件如下所示:
My /etc/ansible/hosts file looks like this:
192.168.0.10 ansible_sudo_pass='passphrase' ansible_ssh_user=user
192.168.0.11 ansible_sudo_pass='passphrase' ansible_ssh_user=user
192.168.0.12 ansible_sudo_pass='passphrase' ansible_ssh_user=user
我不知道发生了什么 - 一切看起来都很好 - 我可以通过 SSH 登录,但 ansible ping 返回相同的错误.
I have no idea what's going on - everything looks fine - I can login via SSH, but ansible ping returns the same error.
详细执行的日志:
<192.168.0.10> 为用户建立 SSH 连接:用户 <192.168.0.10>SSH:执行 ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -oKbdInteractiveAuthentication=no -oPreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey-o PasswordAuthentication=no -o User=user -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.0.10'/bin/sh -c '"'"'( umask 22 && mkdir -p "echo$HOME/.ansible/tmp/ansible-tmp-1463151813.31-156630225033829
" &&echo "<代码>回声$HOME/.ansible/tmp/ansible-tmp-1463151813.31-156630225033829")'"'"''
<192.168.0.10> ESTABLISH SSH CONNECTION FOR USER: user <192.168.0.10> 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=user -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.168.0.10 '/bin/sh -c '"'"'( umask 22 && mkdir -p "
echo $HOME/.ansible/tmp/ansible-tmp-1463151813.31-156630225033829
" && echo "echo $HOME/.ansible/tmp/ansible-tmp-1463151813.31-156630225033829
" )'"'"''
你能以某种方式帮助我吗?如果我必须在本地模式下使用ansible(-c local),那么它就没用了.
Can you help me somehow? If I have to use ansible in local mode (-c local), then it's useless.
我尝试删除 ansible_sudo_pass 和 ansible_ssh_user,但没有帮助.
I've tried to delete ansible_sudo_pass and ansible_ssh_user, but it did'nt help.
推荐答案
您还需要更改 ansible_ssh_pass
或 ssh 密钥,例如我在库存文件中使用它:
You need to change the ansible_ssh_pass
as well or ssh key, for example I am using this in my inventory file:
192.168.33.100 ansible_ssh_pass=vagrant ansible_ssh_user=vagrant
之后我就可以连接到远程主机了:
After that I can connect to the remote host:
ansible all -i tests -m ping
结果如下:
192.168.33.100 | SUCCESS => {
"changed": false,
"ping": "pong"
}
希望能帮到你.
编辑:ansible_ssh_pass
&ansible_ssh_user
在最新版本的 Ansible 中不起作用.它已更改为 ansible_user
&ansible_pass
EDIT: ansible_ssh_pass
& ansible_ssh_user
don't work in the latest version of Ansible. It has changed to ansible_user
& ansible_pass
这篇关于ansible SSH 连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!