Changing host_key_checking
to false
for all hosts is a very bad idea.
The only time you want to ignore it, is on "first contact", which these two tasks will accomplish:
- name: Check SSH known_hosts for {{ inventory_hostname }}
local_action: shell ssh-keygen -F {{ inventory_hostname }}
register: checkForKnownHostsEntry
failed_when: false
changed_when: false
ignore_errors: yes
- name: Add {{ inventory_hostname }} to SSH known hosts automatically
when: checkForKnownHostsEntry.rc == 1
changed_when: checkForKnownHostsEntry.rc == 1
set_fact:
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
So we only turn off host key checking if we don't have the host key in our known_hosts
file.