Skip to content

Instantly share code, notes, and snippets.

@cizario
Forked from JonTheWong/ovh-centos7-hostname
Created May 2, 2017 16:04
Show Gist options
  • Save cizario/c2b7541d21e0044d963005729f2129da to your computer and use it in GitHub Desktop.
Save cizario/c2b7541d21e0044d963005729f2129da to your computer and use it in GitHub Desktop.
OVH - CentOS 7 - Change Hostname
I'm writting this gist for anyone who is having problems updating their OVH Public Cloud hostname on CentOS 7
The issue:
When ordering a public cloud instance and setting the instance name to sub.domain.tld and then eventually changing that sub
the settings don't seem to update on OVH side.
It looks like systemd-hostnamed still pulls the original hostname from what i'm guessing is the datastore on OpenStack. (unconfirmed)
The solution:
When deploying a new instance, you can check what is being pulled using;
hostnamectl status
My solution after two hours of research, is pretty simple.
update line 14 of /etc/cloud/cloud.cfg and add "reserve_hostname: true" the line might not be important but its assume to be at the top of the config
I've accomplished this using ansible as part of my deployment with the following playbook rules.
command: sed -i '14i\preserve_hostname':' true' /etc/cloud/cloud.cfg
This will save the last hostnamectl setting.
So if you plan to automize this you'll need to run;
command: hostnamectl --transient set-hostname {{ inventory_hostname }}
command: hostnamectl --static set-hostname {{ inventory_hostname }}
Then execute the sed command above and reboot.
This solves the hostname delema, but does not update /etc/hosts for this you'll need to create a template file (assuming youre deploying on ansible)
I've tried to find an automated way, but since cloud-init is pulling the settings from (assumed) the OpenStack data store we fall in to the same problem.
My solution was to override /etc/hosts with an ansible template (j2).
127.0.0.1 {{ inventory_hostname }} {{ ansible_hostname }}
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
# The following lines are desirable for IPv6 capable hosts
::1 {{ inventory_hostname }} {{ ansible_hostname }}
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
Hope this helps anyone else with the same problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment