2015-02-06 66 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