`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.
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 serverBeginnerThe playbook hangs for ever at "Gathering Facts" on one hostIntermediate`Failed to connect to the host via ssh: Too many authentication failures`Intermediate