2015-02-06 79 views
0

我的清单文件ansible平模块连接失败

bash ~ cat inventory 

输出

[webservers] 
testserver ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 

当我尝试连接

bash ~ ansible 127.0.0.1 -i inventory -m ping 

它得到了成功的

127.0.0.1 | success >> { 
    "changed": false, 
    "ping": "pong" 
} 

当我使用网络服务器从inventory file

bash ~ ansible webservers -i inventory -m ping 

它失败,下面的错误

testserver | FAILED => SSH encountered an unknown error 
    during the connection. We recommend you re-run the command using -vvvv, 
which will enable SSH debugging output to help diagnose the issue 

我能想出的这个问题

+0

您是否尝试在命令末尾添加-vvvv标志以查看正在使用的SSH命令以及可能产生的错误? – 2015-02-06 16:46:54

+0

您的testserver | FAILED => SSH遇到未知错误,不是网络服务器,请检查它 – 2015-02-07 15:47:14

回答

1

你有一个SSH服务器侦听端口2222?你的第一个例子...

ansible 127.0.0.1 -i inventory -m ping 

...将连接端口22,因为这是在您的清单文件默认并没有什么会覆盖。

你的第二个例子......

ansible webservers -i inventory -m ping 

...使用你的资源文件中的以下条目:

[webservers] 
testserver ansible_ssh_host=127.0.0.1 ansible_ssh_port=2222 

其中规定ansible_ssh_port明确的值,导致Ansible尝试连接在端口2222上。

+0

端口是2222,我使用流浪netstat -an | grep 2222 tcp4 0 0 127.0.0.1.2222 *。* LISTEN – anish 2015-02-07 03:42:26

+0

您是否可以手动将ssh连接到端口2222?例如'ssh -p 2222 @ localhost' – larsks 2015-02-07 21:59:56