执行报错
[root@centos ansible]# ansible host4 -m ping
192.168.13.123 | 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."
}
hosts文件
[root@centos ansible]# pwd
/etc/ansible
[root@centos ansible]# vim hosts![]()
报错原因
主机第一次进行ssh连接,需要输入一个yes将key字符串加入到 ~/.ssh/known_hosts 文件中
解决方法有两种
- 第一种
###手动进行一次ssh连接即可
[root@centos ansible]# ssh 192.168.13.123
The authenticity of host '192.168.13.123 (192.168.13.123)' can't be established.
ECDSA key fingerprint is SHA256:SvKSmafMPnAarQsK7y20jZuB/ekIrjgRRXxL/xVt0bQ.
ECDSA key fingerprint is MD5:42:fd:92:e4:83:8a:7f:20:89:9a:f8:d0:c8:a1:14:de.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.13.123' (ECDSA) to the list of known hosts.
root@192.168.13.123's password:
Last login: Wed Sep 18 10:29:10 2024 from 192.168.13.1
###执行完之后 就可以执行ansible命令 比较繁琐
- 第二种取消检查key
###ansible的配置文件
[root@centos ansible]# pwd
/etc/ansible
[root@centos ansible]# vim ansible.cfg
host_key_checking = False #设置是否检查SSH主机的密钥,值为True/False。关闭后第一次连接不会提示配置实例

###重新执行 成功
[root@centos ansible]# ansible host4 -m ping
192.168.13.122 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.13.113 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.13.123 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
192.168.13.121 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}