Bypass SSH Host Key Checking in Ansible

Author Avatar

SiriusKoan

  ·  1 min read

When Ansible connects to a new host, the connection may fail if that host’s SSH key is not already present in known_hosts. In test environments, short-lived machines, or CI workflows, it can be useful to bypass that check.

Disable Ansible Host Key Checking for Unknown Hosts #

The simplest approach is to set this environment variable:

export ANSIBLE_HOST_KEY_CHECKING=False

This tells Ansible to bypass SSH host key checking during connection.

Ignore Existing Known Hosts #

If you also want to bypass known_hosts checks, you can pass SSH options through ANSIBLE_SSH_COMMON_ARGS, point UserKnownHostsFile to /dev/null, and disable strict host key checking:

export ANSIBLE_SSH_COMMON_ARGS='-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'

The important part is UserKnownHostsFile=/dev/null, which avoids using a real known_hosts file. Combined with StrictHostKeyChecking=no, SSH will not stop on host key verification.

References #