ansible:Using a SSH password instead of a key is not possible because Host Key checking
阿新 • • 發佈:2021-04-23
問題背景
當設定好ansible的hosts後,嘗試用ansible去連線host裡設定的主機。
我使用的是162主機去連線163主機:
如果你之前從來沒有連線過163主機,執行後會報錯
[[email protected] ~]# ansible -i /etc/ansible/hosts web-servers -m ping
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to
see details
192.168.1.163 | FAILED! => {
"msg" : "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to manage this host."
問題原因
這是因為你控制端和被控制端第一次通訊時,需要新增指紋
解決方案
有兩種解決方案:
方法1 . 可以直接修改配置檔案
vim /etc/ansible/ansible.cfg
然後在執行命令
[[email protected] ~]# ansible -i /etc/ansible/hosts web-servers -m ping
[WARNING]: Invalid characters were found in group names but not replaced, us
see details
192.168.1.163 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python" : "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
可以看到已經執行成功了。
方法2:直接登陸SSH,留下指紋即可
使用ssh 登陸遠端主機,只要登陸過一次,下次就不會報錯。