2016-11-29 80 views
-1
ping通我的遠程機器

我想使用以下命令我的遠程Linux機器:無法通過Ansible

ansible remote -m ping -vvvv 

我得到如下回應:

[[email protected] ansible]# ansible remote -m ping -vvvv 
Using /etc/ansible/ansible.cfg as config file 
Loaded callback minimal of type stdout, v2.0 
<192.41.50.9> ESTABLISH SSH CONNECTION FOR USER: root 
<192.41.50.9> SSH: EXEC sshpass -d12 ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 192.41.50.9 '/bin/sh -c '"'"'(umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1480431200.39-212981181831507 `" && echo ansible-tmp-1480431200.39-212981181831507="` echo $HOME/.ansible/tmp/ansible-tmp-1480431200.39-212981181831507 `") && sleep 0'"'"'' 
192.41.50.9 | UNREACHABLE! => { 
"changed": false, 
"msg": "Failed to connect to the host via ssh.", 
"unreachable": true 
} 

hosts文件是這樣的:

[remote] 
192.41.50.9 

[remote:vars] 
ansible_ssh_user=root 
[email protected] 
ansible_ssh_port=22 

當我想ssh到我的遠程計算機,這是我的了:

[[email protected] ansible]# ssh [email protected] 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!  @ 
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! 
Someone could be eavesdropping on you right now (man-in-the-middle attack)! 
It is also possible that a host key has just been changed. 
The fingerprint for the RSA key sent by the remote host is 
86:d2:ca:8e:aa:8a:ce:25:c7:e5:31:7e:2a:c0:11:7f. 
Please contact your system administrator. 
Add correct host key in /root/.ssh/known_hosts to get rid of this message. 
Offending RSA key in /root/.ssh/known_hosts:3 
RSA host key for 192.41.50.9 has changed and you have requested strict checking. 
Host key verification failed. 

什麼可能是這個連接失敗的原因是什麼?

+0

你可以運行'ansible remote -m ping -vvvv'並粘貼結果嗎? – user2599522

+0

當我輸入*** ansible remote -m ping -vvvv ***時,我改變了我的問題並顯示了迴應。請檢查一下。謝謝。 – prudhvi

+1

你能從終端上ssh root @ 192.41.50.9'嗎? – user2599522

回答

0

如果你讀了一個shell中的輸出,你會發現,

  1. 你被一箇中間人攻擊(不太可能)
  2. SSH密鑰在連接服務器已經改變(因爲你重新創建並保持相同的IP)。

如果你的情況是後者,你可以添加以下部分在ansible配置文件ansible.cfg

[defaults] 
host_key_checking=False 
+0

我又得到了同樣的錯誤。我的一位同事在**。rsa pub **文件中做了一些工作,因爲我無法連接。我認爲這是問題。感謝您提出寶貴的建議。我會嘗試更換我的機器。 – prudhvi

0

我沒有足夠的信譽發表評論或給予好評,但user2599522有你的答案,或者至少有一個。

假設你正在使用的根和總是試圖192.41.50.9主機上,運行:

ssh-keygen -f "/root/.ssh/known_hosts" -R 192.41.50.9 

這將刪除以前的指紋,讓你接受了新的。 原因正是他所說的。

此外,他的解決方案是永久性的。使用它對開發很有用,因爲它總是適用。我建議的那個將會工作一次,直到你再次改變主機。

0

我用我的私人IP替換了公共IP,它運行良好。現在,我能夠正確地ping我的遠程機器。