使用Ansible出现错误消息:’FAILED: 服务器的主机密钥不匹配!’

在ansible.cnf中将host_key_checking设置为False。

如果在hosts文件中有多个相同主机的情况下进行SSH连接

# cat hosts 
[local]                    
127.0.0.1

[webservers]
docker  ansible_ssh_port=22 ansible_ssh_host=192.168.1.5
ssh1    ansible_ssh_port=2222 ansible_ssh_host=192.168.1.5
ssh2    ansible_ssh_port=2223 ansible_ssh_host=192.168.1.5
# ansible-playbook -i hosts site.yml --check
PLAY [all nodes] **************************************************************

GATHERING FACTS *************************************************************** 
fatal: [ssh1] => {'msg': 'FAILED: Host key for server 192.168.1.5 does not match!', 'failed': True}
fatal: [ssh2] => {'msg': 'FAILED: Host key for server 192.168.1.5 does not match!', 'failed': True}
ok: [docker]

更改ansible.cfg

#diff -u /etc/ansible/ansible.cfg_ /etc/ansible/ansible.cfg
--- /etc/ansible/ansible.cfg_   2014-08-07 08:36:30.000000000 +0900
+++ /etc/ansible/ansible.cfg    2014-09-19 17:34:11.678637384 +0900
@@ -36,7 +36,7 @@
 #roles_path    = /etc/ansible/roles

 # uncomment this to disable SSH key host checking
-#host_key_checking = False
+host_key_checking = False

 # change this for alternative sudo implementations
 sudo_exe = sudo
/etc/ansible/zabbix #

好的。

# ansible-playbook -i hosts site.yml --check

PLAY [all nodes] **************************************************************

GATHERING FACTS ***************************************************************
ok: [ssh1]
ok: [docker]
ok: [ssh2]
广告
将在 10 秒后关闭
bannerAds