ansible SSH连接失败

Tho*_*mas 28 connection ssh ansible

我试图在多个服务器上运行ansible角色,但是我收到一个错误:

致命:[192.168.0.10]:无法访问!=> {"已更改":false,"msg":"无法通过ssh连接到主机.","无法访问":true}

我的/ etc/ansible/hosts文件如下所示:

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
Run Code Online (Sandbox Code Playgroud)

我不知道发生了什么 - 一切看起来很好 - 我可以通过SSH登录,但ansible ping返回相同的错误.

来自详细执行的日志:

<192.168.0.10>为用户建立SSH连接: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")''''''

你能以某种方式帮助我吗?如果我必须在本地模式(-c local)中使用ansible,那么它就没用了.

我试图删除ansible_sudo_pass和ansible_ssh_user,但它没有帮助.

Arb*_*zar 42

您需要更改ansible_ssh_pass以及ssh键,例如我在库存文件中使用它:

192.168.33.100 ansible_ssh_pass=vagrant ansible_ssh_user=vagrant
Run Code Online (Sandbox Code Playgroud)

之后我可以连接到远程主机:

ansible all -i tests -m ping
Run Code Online (Sandbox Code Playgroud)

结果如下:

192.168.33.100 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
Run Code Online (Sandbox Code Playgroud)

希望对你有所帮助.

  • 是! 我错过了ansible_ssh_pass变量.现在一切都像魅力一样.非常感谢! (3认同)

小智 6

mkdir /etc/ansible
cat > hosts
default ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 ansible_ssh_user=vagrant ansible_ssh_private_key_file=.vagrant/machines/default/virtualbox/private_key
Run Code Online (Sandbox Code Playgroud)

转到您的剧本目录并运行ansible all -m ping