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.
More on Connection and SSH Failures
`UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: Permission denied (publickey,password)."}`Beginner`UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host 10.0.1.15 port 22: Connection timed out"}`Beginner`UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host web01 port 22: Connection refused"}`Beginner`Host key verification failed.` after rebuilding a serverBeginner`Failed to connect to the host via ssh: Too many authentication failures`Intermediate`fatal: [web01]: UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: Shared connection to web01 closed."}` mid-runIntermediate