I’ve been having trouble with this for a while…
On Ubuntu 14.04 (current LTS), the ansible_fqdn variable often only contains the hostname, not the hostname+domainname.
I’ve tried to fix this by having ansible insert a line like this in /etc/hosts, but it didn’t help.
127.0.1.1 {{ inventory_hostname }} {{ ansible_hostname }}
(Which expands to 127.0.1.1 hostname.domain.name hostname)
so the fqdn gets set first by trying to do reverse dns, which would
not use that /etc/hosts entry, if that fails it falls back to using
the gethostname function which does not guarantee a fully qualified
domain name.
run 'hostname' on the command line, you should see the same output.
I was able to use the inventory_hostname as a workaround in templates, but I’m not the only one here, and other people in the company are likely to continue to use the ansible_fqdn as it’s the widely-documented way to get the FQDN - and does work in some places.
I eventually tracked the problem with the reverse DNS lookups down, and it seems to have fixed the problem.
First it seems like it is dns issue- rDNS.
For troubleshooting get the ip address of host manually,
and try to run host ip, it should return something (fqdn, if it doesn’t go fix DNS entry)