Disable host-key checking in ansible

If you want to disable host-key checking in the Ansible ad-hoc command, there are simple steps, but it’s important to disable it to make life easier.

Disable host-key checking in ansible

Why disable it?

Before we get into how to disable let’s see why to disable it?

Ansible works on SSH protocol and SSH maintains and checks the database of all the hosts which have been ever accessed.

All the host and the keys are stored in the file ~/.ssh/known_hosts so whenever you SSH to the server it checks in the known host’s file and if the host doesn’t exist, you will be asked to store new keys.

If you are using Ansible and if the hosts are not added in known_hosts ansible-playbook will fail, so it makes sense to disable host key checking.

How to Disable host-key checking in ansible?

first, run the command below.


Now, once you have disabled host key checking run your ansible ad-hoc command.

# ansible all -i inventory -m shell -a 'uptime'

Run Ansible Adhoc command with Sudo

# ansible all -i inventory.yml -m shell -a 'uptime' -K --become

The above method was to disable host key checking for ansible ad-hoc command, however, you want to disable it globally so that you can run ansible-playbook without any problems you will have to add the code below in the file /etc/ansible/ansible.cfg.

host_key_checking = False

I hope now you know how to disable host-key checking in ansible. Just you know that ansible is a vast topic, and it’s impossible to cover them all. However, you can comment on what you want us to post and we will try our best. Meanwhile, you can read ansible docs 🙂

Leave a Comment