OpenStack keeps resetting my hostname

Visits: 1087

Openstack sets your hostname with cloud init on each boot. When you create the instance, you should assign it a name with full FQDN. This is absolutely required by Openshift.

I did the following:

 

Check out the Original of this article from my blog at work:  Octopus Computer Solutions  

Hostnames and FQDN are often far from what you desire.

Very often in the cloud, be it Openstack, Amazon, Azure or GC, The default hostname is not what you need. When you change the name, it often reverts after reboot. This is due to Cloud Init run at every boot.

Change a Red Hat Openstack instance  FQDN hostname in a few simple commands

First update the instance name, since otherwise when you reboot cloud init with change the name back. (this can be disabled in /etc/cloud/cloud.cfg)
 $ openstack server set PRESENT-INSTANCE-NAME-OR-UUID   --name  NEW-host-NAME (not fqdn)
Now ssh into the Server instance
Edit the /etc/hosts file
$ sudo vi /etc/hosts
At the end of the file put
YOUR_IP_ADDRESS   YOUR-FQDN-HOSTNAME_WITHDOMAIN_NAME    YOUR-HOSTNAME
Then run
$ sudo hostnamectl set-hostname YOUR-FQDN-HOSTNAME_WITHDOMAIN_NAME 

If it isnt a cloud instance the just changing the hosts and set-hostname should work.
For other clouds like AWS and AZURE disable the hostname values in /etc/cloud/cloud.cfg
This should also work for Centos, Fedora an Amazon Linux

to install FQDN on openstack instances that are already configured

  • hostname and hostname -f should be the same
  • in order to do this i
    created file

/etc/cloud/cloud.cfg.d/99_hostname.cfg

#cloud-config
hostname: foo
fqdn: foo.bar.woot

  • I editted /etc/hostname adding full fqdn
  • I removed the
    hostname stuff from
    /etc/cloud/cloud.cfg
  • also set with fqdn with hostname command
    hostname foo.bar.woot

 

Another easy way is to just drop a file inside of /etc/cloud/cloud.cfg.d. Call it 99_hostname.cfg and add something like the following: #cloud-config hostname: foo fqdn: foo.bar.woot

Source: OpenStack keeps resetting my hostname | Adam Young’s Web Log

Leave a Reply