Interview Prep/Ansible/Connection and SSH Failures

`fatal: [web01]: UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: Shared connection to web01 closed."}` mid-run

IntermediateTroubleshootingConnection and SSH Failures
Answer

Likely causes → The SSH ControlPersist socket is stale, the connection dropped mid-run (NAT idle timeout), or the host rebooted.

Diagnose → Look for ControlPath sockets in ~/.ansible/cp/ and test ssh -O check host.

Fix →

rm -rf ~/.ansible/cp/*

and set keepalives: ssh_args = -o ServerAliveInterval=30 -o ServerAliveCountMax=5 -o ControlMaster=auto -o ControlPersist=60s.

Prevent → Use keepalives on long runs, and the reboot module for restarts.

All Ansible questions Roadmap: Ansible

More on Connection and SSH Failures