SSH works from the shell but Ansible says `UNREACHABLE` with `Could not resolve hostname`
BeginnerTroubleshootingConnection and SSH Failures
Answer
Likely causes → Inventory name is not resolvable DNS and ansible_host is not set; shell uses ~/.ssh/config aliases but the inventory uses a different name.
Diagnose →
getent hosts web01
ansible-inventory --host web01 | jq .ansible_host
Fix → Set ansible_host: 10.0.1.15, or add the alias to DNS. Ansible honours ~/.ssh/config too, but only for the name it connects with.
Prevent → Keep ansible_host in inventory (or compose it dynamically).
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