2016-11-29 81 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我的远程机器。