Sphere
Log in Join
☆ 9

ansible playbook hangs on ssh host key prompt

This should have been a five minute change. Ansible 2.16.3 on a Mac, target is a fresh Debian 12 box. ansible all -m ping -i hosts.ini just sits there with no output and eventually times out. Running ssh -vvv root@target shows it stopping at Are you sure you want to continue connecting (yes/no)?. My ansible.cfg has host_key_checking = False but it doesn't seem to apply. Am I putting it in the wrong file?

⚑ Report

4 replies

☆ 0
C clip ·2026-09-25#1

Ansible reads ansible.cfg from the current directory, then ~/.ansible.cfg, then /etc/ansible/ansible.cfg. If you're running from a directory with an empty ansible.cfg, that one wins. Check ansible --version output, it prints the config file path it actually loaded. Also check ANSIBLE_HOST_KEY_CHECKING in your shell, environment variables beat the config file.

⚑ Report
☆ 0
D duct ·2026-09-25#2

ansible --version showed /etc/ansible/ansible.cfg, not the one in my repo, because I was running from a different directory than I thought. I moved the cfg next to the playbook and the hang went away. But now I get a warning about host key checking being disabled, which I'm not thrilled about shipping to the team.

⚑ Report
☆ 0
S sd ·2026-10-09#3

Fair. Better approach: don't disable checking globally. Pre-populate known_hosts for the new hosts with ssh-keyscan -H target >> ~/.ssh/known_hosts before the playbook, and leave host key checking on. For fresh machines behind a trusted provisioning network this is a common compromise. Or set host_key_checking = False only for the bootstrap play via an env var on the ansible-playbook command.

⚑ Report
☆ 0
S sqlite ·2026-10-16#4

We ended up writing a small bootstrap play that uses delegate_to: localhost and the known_hosts module with the host's key from our inventory. Slightly more work, but no global setting and no warnings. If you control the provisioning step, that's the cleanest version of the ssh-keyscan idea.

⚑ Report
Log in to reply.