是的,您可以在库存/主机级别设置。
有了已经接受的答案,我认为这是对如何在库存级别处理此问题的更好答案。我认为通过将这种不安全的设置隔离到所需的主机(例如测试系统、本地开发机器)来更安全。
您可以在库存级别做的就是添加
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
或
ansible_ssh_extra_args='-o StrictHostKeyChecking=no'
到您的主机定义(请参阅Ansible Behavioral Inventory Parameters)。
如果您使用 ssh 连接类型,而不是 paramiko 或其他类型,这将起作用。
例如,Vagrant 主机定义看起来像……
vagrant ansible_port=2222 ansible_host=127.0.0.1 ansible_ssh_common_args='-o StrictHostKeyChecking=no'
或
vagrant ansible_port=2222 ansible_host=127.0.0.1 ansible_ssh_extra_args='-o StrictHostKeyChecking=no'
然后在不更改任何环境变量的情况下运行 Ansible 即可成功。
$ ansible vagrant -i <path/to/hosts/file> -m ping
vagrant | SUCCESS => {
"changed": false,
"ping": "pong"
}
如果您想为一组主机执行此操作,建议将其作为现有组的补充组变量,如下所示:
[mytestsystems]
test[01:99].example.tld
[insecuressh:children]
mytestsystems
[insecuressh:vars]
ansible_ssh_common_args='-o StrictHostKeyChecking=no'