Interview Prep/Ansible/Connection and SSH Failures

`UNREACHABLE! => {"msg": "Failed to connect to the host via ssh: ssh: connect to host web01 port 22: Connection refused"}`

BeginnerTroubleshootingConnection and SSH Failures
Answer

Likely causes → sshd is not running, listens on another port, or the host is still booting.

Diagnose →

nc -vz web01 22
ssh -p 2222 user@web01          # test an alternate port
# on the host console: systemctl status sshd; ss -tlnp | grep ssh

Fix → Start sshd, or set ansible_port in inventory. After provisioning use wait_for_connection or wait_for on port 22.

Prevent → Add a wait step in provisioning playbooks.

All Ansible questions Roadmap: Ansible

More on Connection and SSH Failures