Ansible "UNREACHABLE" SSH connection failure in CI
Ansible could not establish an SSH connection to a managed host -- a network/firewall block, a wrong address or port, a timeout, or a down host -- so the task never ran.
What this error means
A host shows UNREACHABLE with "Failed to connect to the host via ssh" (connection refused, timed out, or no route). It is distinct from an auth failure: the connection itself did not open.
fatal: [web01]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to
the host via ssh: ssh: connect to host 10.0.3.21 port 22: Connection timed out",
"unreachable": true}Common causes
Network or firewall blocks the runner
A security group, firewall, or missing route prevents the CI runner from reaching the host on the SSH port.
Wrong host/port or host down
A stale inventory address, non-standard port, or a host that is not yet booted leaves the connection with nothing to reach.
How to fix it
Make the host reachable and confirm connectivity
Open the SSH path from the runner and verify before running the play; raise the connection timeout for slow networks.
ansible -i inventory web01 -m ping
# raise SSH connect timeout if the network is slow:
ANSIBLE_TIMEOUT=30 ansible-playbook -i inventory site.ymlFix inventory and routing
- Verify the inventory address and ansible_port are correct.
- Confirm a security group/firewall rule allows the runner to reach the host on SSH.
- Ensure the host is fully booted before the play targets it.
How to prevent it
- Allow the runner egress to the SSH port of target hosts.
- Keep inventory addresses and ports current.
- Run plays on a platform that auto-retries transient network unreachability.