Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set FQDN with ansible?

Tags:

ubuntu

ansible

It seems the recommended method doesn't work well to me:

- name: Set hostname
  hostname: name=mx.mydomain.net

After rebooting, you can see I have problems with fqdn, nothing in /etc/hosts.

root@mx:~# cat /etc/hosts
127.0.0.1   localhost
127.0.1.1   mail mail

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

root@mx:~# cat /etc/hostname
mx.mydomain.net

root@mx:~# hostname
mx.mydomain.net

root@mx:~# hostname -f
hostname: Name or service not known
like image 513
holms Avatar asked Sep 22 '14 17:09

holms


1 Answers

It appears that the documentation for this Ansible module just isn't very clear in exactly what it does. I just took a quick look at the source code for the hostname module on github and it appears that depending on the linux distribution it only invokes /bin/hostname and/or modifies /etc/hostname, /etc/sysconfig/network, or /etc/conf.d/hostname. This module itself doesn't actually modify /etc/hosts in any way.

If you consider this to be a bug in the way that this module works then I'd strongly suggest you submit a bug report to the Ansible developers, which you can do here. Even if you think the documentation should just be improved then it would be helpful to submit a bug report requesting that the documentation be fixed.

like image 67
Bruce P Avatar answered Oct 19 '22 03:10

Bruce P