Interview Prep/Ansible/Connection and SSH Failures

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).

All Ansible questions Roadmap: Ansible

More on Connection and SSH Failures