ansible执行命令报错Using a SSH password instead of a key is not possible because Host Key checkingis enabl

ansible执行命令报错

192.168.100.10 | FAILED | rc=-1 >>
Using a SSH password instead of a key is not possible because Host Key checkingis enabled and sshpass does not support this. Please add this host’s fingerprint to your known_hosts file to manage this host.

从输出提示上基本可以了解到由于在本机的~/.ssh/known_hosts文件中并有fingerprint key串,ssh第一次连接的时候一般会提示输入yes 进行确认为将key字符串加入到 ~/.ssh/known_hosts 文件中

基于这个原因,可以修改/etc/ansible/ansible.cfg配置文件

hosts配置如下:
vi /etc/ansible/hosts

[local]
127.0.0.1
[test1]
192.168.100.11  ansible_ssh_user=root ansible_ssh_pass=123456
[test2]
192.168.100.12  ansible_ssh_user=root ansible_ssh_pass=123456
[test3]
192.168.100.10  ansible_ssh_user=root ansible_ssh_pass=123456
[test4]
192.168.100.9  ansible_ssh_user=root
"/etc/ansible/hosts" 53L, 1301C

解决方法两种:

第一种:在本地先SSH登录一下对方设备,下次ansible 就可以正常操作了,但是比较麻烦

[root@shanan ~]# ssh root@192.168.100.11
The authenticity of host '192.168.100.11 (192.168.100.11)' can't be established.
ECDSA key fingerprint is SHA256:z+83zi+ptU8EEYf7ccqK5tDPDLa8ekQe+pKQ+UKX72Y.
ECDSA key fingerprint is MD5:a9:be:c0:fa:44:1b:e6:84:83:78:55:2b:9f:88:c7:d6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.11' (ECDSA) to the list of known hosts.
root@192.168.100.11's password:
Last login: Sat Dec 26 19:39:43 2020 from 192.168.100.1

第二种:设置参数为不检查key

vi /etc/ansible/ansible.cfg
在文件中进行搜索定位到

:/host_key_checking

# uncomment this to disable SSH key host checking
#host_key_checking = False
修改后:

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

保存退出,重新执行命令测试:
解决!!!

[root@shanan ~]# ansible test3  -a 'ls'
192.168.100.10 | CHANGED | rc=0 >>
anaconda-ks.cfg
original-ks.cfg
下载
公共
图片
文档
桌面
模板
视频
音乐
  • 11
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值