CentOS 7: update-hostname always overwrites hostname
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init |
Expired
|
Medium
|
Unassigned |
Bug Description
On CentOS 7 (systemd based), with cloud-init 0.7.5, cc_update_hostname will *always* overwrite the hostname, even if it shouldn't.
This is pretty easy to reproduce:
1) Add a 'hostname: metadata.
2) Run 'hostnamectl set-hostname test.example.com'
3) Reboot the server
4) Check the hostname, it'll still be 'metadata.
5) Repeat 2-4, hostname will still be set
Looking at the code, this is because rhel.py doesn't populate the previous-hostname file correctly:
def _write_
if self._dist_
else:
}
So, Distros:
The fix here seems pretty simple, we just need to update previous-hostname as well when running hostnamectl. I attached a patch that does this, though I don't know the best way to implement this.. my patch fails if cloud-init's data path is changed
Related branches
- Server Team CI bot: Needs Fixing (continuous-integration)
- Scott Moser: Needs Information
- Joshua Harlow (community): Approve
-
Diff: 17 lines (+3/-3)1 file modifiedcloudinit/distros/rhel.py (+3/-3)
Changed in cloud-init: | |
status: | New → Confirmed |
importance: | Undecided → Medium |
tags: | added: centos |
I can confirm this bug. If you place the previous-hostname file manually it stops changing the hostname on every reboot. As a workaround i installed cloud-init- 0.7.5-6. el7 (epel).