update_hostname module fails on CentOS/RHEL with systemd

Bug #1736174 reported by Albert Beauregard
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
cloud-init
Expired
Medium
Unassigned

Bug Description

Cloud provider: OpenStack

#cloud-config
hostname: somehostname.somedomain
fqdn: somehostname.somedomain

 __init__.py[INFO]: /var/lib/cloud/data/previous-hostname differs from /etc/hostname, assuming user maintained hostname.

Error message is a little bit misleading, since when uses_systemd(), /etc/hostname isn't actually read, instead, the result of util.subp(['hostname']) is used.

Also, this comparison/test will never succeed, because when uses_systemd() and filename.endswitch('/previous-hostname'), the return is stripped of cr/lf, however, the result of util.subp(['hostname']) will contain a lf, and it is not being stripped:

(from rhel.py)
if self.uses_systemd() and filename.endswith('/previous-hostname'):
            return util.load_file(filename).strip()
        elif self.uses_systemd():
            (out, _err) = util.subp(['hostname'])
            if len(out):
                return out
            else:
                return default

The simplest solution appears to be to add .strip() to return out; but this fix may have other implications.

Tags: rhel centos
Revision history for this message
Martin Steigerwald (ms-proact) wrote :

I am currently preparing CentOS 7.5 Cloud Init images for my Linux trainings and am also affected by this bug. It might also be good to be able to disable this flaky auto detection, as there is already a config option `preserve_hostname` for preserving the hostname.

Revision history for this message
Martin Steigerwald (ms-proact) wrote :

Your work-around appears to work, thanks Albert.

Revision history for this message
Albert Beauregard (albeauregard) wrote :

I'm not sure how to get this reviewed by a contributor. It doesn't look like my bug report has had any action as it is still status New.

Revision history for this message
Martin Steigerwald (ms-proact) wrote :

The check of course also fails when using cloud-init to adapt a cloud-init image where cloud-init initially has been run:

2018-05-14 14:29:53,255 - __init__.py[INFO]: /var/lib/cloud/data/previous-hostname differs from /etc/hostname, assuming user maintained hostname.
2018-05-14 14:29:53,255 - __init__.py[INFO]: System hostname centos1.[…], previous hostname centostemplate.[…]

Interestingly enough it still renamed the host:

[root@centos1 ~]# hostname
centos1.qs.de

My stance of it: Either cloud-init manages the hostname or another tool like Puppet does it. Mixing both is a recipe for trouble, if you ask me.

no longer affects: cloud-init (CentOS)
Revision history for this message
Ryan Harper (raharper) wrote :

Thank you for filing the bug. Is this bug still affecting you?

Changed in cloud-init:
importance: Undecided → Medium
status: New → Triaged
status: Triaged → Incomplete
Revision history for this message
Albert Beauregard (albeauregard) wrote :

It does not appear there has been any change to the source.
We continue to patch this internally in our environment.

Revision history for this message
James Falcon (falcojr) wrote :
Changed in cloud-init:
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.