2017-09-28 101 views
0

我有一个主人和一个奴隶。
我可以通过SSH从主站连接到从站。
Ansible 无法连接从主机到从机的Ansible说:“权限被拒绝(公钥,密码)”

问题:我在做什么错误,以至于无法连接,但ssh可以吗?

从主

成功连接到通过ssh奴隶

[email protected]:~$ ssh slave.local 
Enter passphrase for key '/home/vagrant/.ssh/id_rsa': 
[email protected]'s password: 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-87-generic x86_64) 

* Documentation: https://help.ubuntu.com 
* Management:  https://landscape.canonical.com 
* Support:  https://ubuntu.com/advantage 

17 packages can be updated. 
9 updates are security updates. 


---------------------------------------------------------------- 
    Ubuntu 16.04.3 LTS       built 2017-09-08 
---------------------------------------------------------------- 
Last login: Thu Sep 28 15:20:21 2017 from 10.0.0.10 
[email protected]:~$ 

Ansible错误: “权限被拒绝(公钥,密码)

[email protected]:~$ ansible all -m ping -u vagrant 
The authenticity of host 'slave.local (10.0.0.11)' can't be established. 
ECDSA key fingerprint is SHA256:tRGlinvTj/c2gpTayZ/mYzyWbs63s+BUX81TdKJ+0jQ. 
Are you sure you want to continue connecting (yes/no)? yes 
Enter passphrase for key '/home/vagrant/.ssh/id_rsa': 

slave.local | UNREACHABLE! => { 
"changed": false, 
"msg": "Failed to connect to the host via ssh: Warning: Permanently added 'slave.local' (ECDSA) to the list of known hosts.\r\nPermission denied (publickey,password).\r\n", 
"unreachable": true 
} 

这是我的hosts文件

[email protected]:~$ cat /etc/ansible/hosts 
[web] 
slave.local 
+2

运行看看ssh命令有什么问题。 –

+0

是否可以通过ssh进入[email protected]?您的手动ssh示例登录到[email protected]。 – Rickkwa

+0

@Konstantin不幸vvvv不提供任何其他信息。但我加了 – Skip

回答

0

的解决方案是在OpenSSH格式的私钥添加到文件/home/vagrant/.ssh/id_rsa
这是ansible正在寻找的关键。

这是我能找到,通过启动在详细模式ansible,使用键 “-vvvv”

ansible all -m ping -u vagrant -vvvv 

详细输出为

用`-vvv`开关
10.0.0.11 | UNREACHABLE! => { 
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g 1 Mar 2016\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket \"/home/vagrant/.ansible/cp/a72f4dc97e\" does not exist\r\ndebug2: resolving \"10.0.0.11\" port 22\r\ndebug2: ssh_connect_direct: needpriv 0\r\ndebug1: Connecting to 10.0.0.11 [10.0.0.11] port 22.\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug1: fd 3 clearing O_NONBLOCK\r\ndebug1: Connection established.\r\ndebug3: timeout: 10000 ms remain after connect\r\ndebug1: key_load_public: No such file or directory\r\ndebug1: identity file /home/vagrant/.ssh/id_rsa type -1\r\ndebug1: key_load_public: No such file or directory\r\ndebug1: identity file ...