debian: cloud hostname ignored by Jessie

5af25b5f fixed the hostname of Debian images to "debian" since a lack of
hostname definition set the hostname to "(None)".

It has been done by introducing /etc/cloud/cloud.cfg.d/01_hostname.cfg
with content:

  hostname: debian

Review supposed the hostname would be overriden by cloud meta-data. That
might have stand true for Wheezy but it is not the case for Jessie.

cloud-init 0.7.6 ignores cloud metadata whenever "hostname" or "fqdn"
are set in a config file. Roughly:

    # no fqdn set, get fqdn from cloud
    # get hostname from cfg if available otherwise cloud
    fqdn = cloud.get_hostname(fqdn=True)
    if "hostname" in cfg:
        # hashar: set from config file NOT cloud
        hostname = cfg['hostname']
    else:
        # fallback to cloud
        hostname = cloud.get_hostname()

Relevant code is
https://github.com/number5/cloud-init/blob/0.7.6/cloudinit/util.py#L839-L860

Only inject "hostname: debian" for the Wheezy release.

Bug: https://phabricator.wikimedia.org/T117283
Change-Id: I6e2522bd725cbf9651f11c76ecdc72ecbc92f402
This commit is contained in:
Antoine Musso 2015-10-30 22:34:10 +01:00
parent 94a7a7cf67
commit 23be09ce35

View File

@ -37,5 +37,10 @@ if [ "$DIB_DEBIAN_ALT_INIT_PACKAGE" != "sysvinit" ]; then
/etc/apt/preferences.d/sysvinit > /etc/apt/preferences.d/sysvinit
fi
# specify a hostname so that cloud-init does not default to (None)
echo 'hostname: debian' > /etc/cloud/cloud.cfg.d/01_hostname.cfg
# Since Jessie, when either 'hostname' or 'fqdn' are in a config file, it
# considers them as authoritative and would only use cloud meta data as a
# fallback.
if [ "$DIB_RELEASE" = 'wheezy' ]; then
# specify a hostname so that cloud-init does not default to (None)
echo 'hostname: debian' > /etc/cloud/cloud.cfg.d/01_hostname.cfg
fi