Ansible: Failed to connect to the host via ssh
The Context
In our environment, the Azure DevOps build server operates directly from an Ansible management host. We utilize a structure with one inventory file per Azure subscription, triggering baseline configuration pipelines across various projects.
The Error
Recent pipeline runs consistently failed with the following SSH connection error:
fatal: [target-host]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname target-host.domain.local: Name or service not known",
"unreachable": true
}
The Fix
The issue was traced to an explicit ansible_host FQDN override in the inventory’s compose section. The build server’s local DNS resolution was unable to resolve the .domain.local suffix for these specific targets.
By removing (or commenting out) the manual suffix, Ansible defaults to the inventory_hostname, allowing the system’s standard name resolution (DNS/hosts) to handle the connection correctly.
# Issue: Manual FQDN override causing resolution failure
compose:
ansible_host: "{{ inventory_hostname }}.domain.local"
# Resolution: Revert to default hostname resolution
compose:
# ansible_host: "{{ inventory_hostname }}"