Interview Prep/Ansible/Connection and SSH Failures

The playbook hangs for ever at "Gathering Facts" on one host

IntermediateTroubleshootingConnection and SSH Failures
Answer

Likely causes → SSH waiting for a prompt (new host key confirmation or password), a slow DNS lookup on the target, sudo prompting for a password, or a broken shell profile printing output.

Diagnose →

ansible web01 -m setup -vvv
ssh -v web01 true

Check UseDNS in sshd_config and /etc/profile or .bashrc for interactive commands.

Fix → Disable UseDNS, make profiles non-interactive ([[ $- == *i* ]] || return), set timeout = 30, and use ansible_ssh_common_args with -o BatchMode=yes.

Prevent → Use BatchMode and a connect timeout in ansible.cfg.

All Ansible questions Roadmap: Ansible

More on Connection and SSH Failures