How to set host_key_checking=false in ansible inventory file?
Due to the fact that I answered this in 2014, I have updated my answer to account for more recent versions of ansible.
Yes, you can do it at the host/inventory level (Which became possible on newer ansible versions) or global level:
inventory:
Add the following.
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
host:Add the following.
ansible_ssh_extra_args='-o StrictHostKeyChecking=no'
hosts/inventory options will work with connection type ssh and not paramiko. Some people may strongly argue that inventory and hosts is more secure because the scope is more limited.global:
Ansible User Guide - Host Key Checking
- You can do it either in the
/etc/ansible/ansible.cfgor~/.ansible.cfgfile:
[defaults] host_key_checking = False - Or you can setup and env variable (this might not work on newer ansible versions):
export ANSIBLE_HOST_KEY_CHECKING=FalseYes, you can set this on the inventory/host level.
With an already accepted answer present, I think this is a better answer to the question on how to handle this on the inventory level. I consider this more secure by isolating this insecure setting to the hosts required for this (e.g. test systems, local development machines).
What you can do at the inventory level is add
oransible_ssh_common_args='-o StrictHostKeyChecking=no'
to your host definition (see Ansible Behavioral Inventory Parameters).ansible_ssh_extra_args='-o StrictHostKeyChecking=no'
This will work provided you use thesshconnection type, notparamikoor something else).
For example, a Vagrant host definition would look like…
orvagrant ansible_port=2222 ansible_host=127.0.0.1 ansible_ssh_common_args='-o StrictHostKeyChecking=no'
Running Ansible will then be successful without changing any environment variable.vagrant ansible_port=2222 ansible_host=127.0.0.1 ansible_ssh_extra_args='-o StrictHostKeyChecking=no'
In case you want to do this for a group of hosts, here's a suggestion to make it a supplemental group var for an existing group like this:$ 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'
Комментарии
Отправить комментарий