Ansible报错“Using a SSH password instead of a key is not possible because Host Key checking is enable”

执行报错

[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

image-20240918123957960
image-20240918122703226

报错原因

主机第一次进行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。关闭后第一次连接不会提示配置实例
image-20240918122821779
###重新执行 成功
[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"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值