ansible_fqdn only contains the hostname

7,280 views
Skip to first unread message

Toby Wintermute

unread,
Oct 12, 2015, 9:37:43 PM10/12/15
to Ansible Project
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)

Does anyone have other suggestions?

Brian Coca

unread,
Oct 13, 2015, 11:05:42 AM10/13/15
to Ansible Project
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.



--
Brian Coca

Toby Corkindale

unread,
Oct 13, 2015, 7:52:05 PM10/13/15
to ansible...@googlegroups.com
Well I guess the question is: how do I fix it?
It sounds like I need to fix the reverse DNS lookups.

I do note that running "hostname -f" from the command line DOES return the FQDN, by the way, even though "hostname" on its own does not.

-Toby 

Dick Davies

unread,
Oct 14, 2015, 4:50:12 AM10/14/15
to ansible list
Picking through the code it seems to be whatever

socket.getfqdn() 

returns in Python.

side suggestion: why are you needing the hostname? could you just use the inventory name instead in whatever template etc. you're having issues with?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CABEgq96T9ubjgwc%2B1fbte0ExoiezJUzjScp8FORsxDCAwTh%3DuA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Toby Corkindale

unread,
Oct 14, 2015, 7:25:15 PM10/14/15
to ansible list
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.

You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/ReYfcByti08/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.

To post to this group, send email to ansible...@googlegroups.com.

Шалыгин Константин

unread,
Oct 15, 2015, 1:04:29 AM10/15/15
to Ansible Project
ansible_fqdn = host
facter_fqdn = host.domain

I use this last two years, it's comfortable for me.

Murad Mammed

unread,
Jan 19, 2022, 10:44:25 AM1/19/22
to Ansible Project
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)
Reply all
Reply to author
Forward
0 new messages