python ansible api 初次连接报错,pythonansible


fatal: [xxx.xxx.xxx.xxx]: FAILED! => {"failed": true, "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、解决方式:

解决:在ansible 服务器上使用ssh 登陆下/etc/ansible/hosts 里面配置的服务器。然后再次使用ansible 去管理就不会报上面的错误了!但这样大批量登陆就麻烦来。因为默认ansible是使用key验证的,如果使用密码登陆的服务器,使用ansible的话,要不修改ansible.cfg配置文件的ask_pass = True给取消注释,要不就在运行命令时候加上-k,这个意思是-k, --ask-pass ask for SSH password。再修改:host_key_checking= False即可

2、解决方式:

ssh 自动添加hostkey 到 .ssh/know_hosts

当我们用ssh连接到其他linux平台时,会遇到以下提示:

The authenticity of host ‘git.sws.com (10.42.1.88)’ can’t be established.
ECDSA key fingerprint is 53:b9:f9:30:67:ec:34:88:e8:bc:2a:a4:6f:3e:97:95.
Are you sure you want to continue connecting (yes/no)? yes
而此时必须输入yes,连接才能建立。

但其实我们可以在ssh_config配置文件中配置此项,

打开/etc/ssh/ssh_config文件:

找到:
# StrictHostKeyChecking ask
修改为
StrictHostKeyChecking no

这个选项会自动的把 想要登录的机器的SSH pub key 添加到 /root/.ssh/know_hosts 中。


参考:

①、https://blog.csdn.net/longxibendi/article/details/46989735

②、https://blog.csdn.net/qianggezhishen/article/details/48732755


相关内容

    暂无相关文章