在使用ansible时,遇到下面的报错
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.
原因是此主机之前没有ssh连接过,在本机的~/.ssh/known_hosts文件中没有fingerprint key串,ssh第一次连接的时候一般会提示输入yes 进行确认为将key字符串加入到 ~/.ssh/known_hosts 文件中。
要解决此问题,可以通过ansible.cfg文件配置解决
配置文件里有如下的字串
[ssh_connection]
# ssh arguments to use
# Leaving off ControlPersist will result in poor performance, so use
# paramiko on older platforms rather than removing it
#ssh_args = -o ControlMaster=auto -o ControlPersist=60s
可以启用ssh_args,改为
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no
也可以看到下面的部分
# uncomment this to disable SSH key host checking
#host_key_checking = False
取消上面的注释,是一个更好的办法(推荐)