diff options
author | Emanuele Giuseppe Esposito <eesposit@redhat.com> | 2022-05-31 16:03:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 09:03:44 -0500 |
commit | 74e43496f353db52e15d96abeb54ad63baac5be9 (patch) | |
tree | 859c6f38dff44382e9029585e37a26f3c880454d /cloudinit/cmd | |
parent | a918e9e20845bef903b903e89cfdfb97104e6e4d (diff) | |
download | cloud-init-git-74e43496f353db52e15d96abeb54ad63baac5be9.tar.gz |
cc_set_hostname: do not write "localhost" when no hostname is given (#1453)
Systemd used to sometimes ignore localhost in /etc/hostnames, and many programs
like cloud-init used this as a workaround to set a default hostname.
From https://github.com/systemd/systemd/commit/d39079fcaa05e23540d2b1f0270fa31c22a7e9f1:
We would sometimes ignore localhost-style names in /etc/hostname. That is
brittle. If the user configured some hostname, it's most likely because they
want to use that as the hostname. If they don't want to use such a hostname,
they should just not create the config. Everything becomes simples if we just
use the configured hostname as-is.
This behaviour seems to have been a workaround for Anaconda installer and other
tools writing out /etc/hostname with the default of "localhost.localdomain".
Anaconda PR to stop doing that: rhinstaller/anaconda#3040.
That might have been useful as a work-around for other programs misbehaving if
/etc/hostname was not present, but nowadays it's not useful because systemd
mostly controls the hostname and it is perfectly happy without that file.
Apart from making things simpler, this allows users to set a hostname like
"localhost" and have it honoured, if such a whim strikes them.
As also suggested by the Anaconda PR, we need to stop writing default "localhost"
in /etc/hostnames, and let the right service (networking, user) do that if they
need to. Otherwise, "localhost" will permanently stay as hostname and will
prevent other tools like NetworkManager from setting the right one.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
RHBZ: 1980403
Diffstat (limited to 'cloudinit/cmd')
-rwxr-xr-x | cloudinit/cmd/main.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py index fcdaf725..f2d1880a 100755 --- a/cloudinit/cmd/main.py +++ b/cloudinit/cmd/main.py @@ -790,7 +790,7 @@ def _maybe_set_hostname(init, stage, retry_stage): @param retry_stage: String represented logs upon error setting hostname. """ cloud = init.cloudify() - (hostname, _fqdn) = util.get_hostname_fqdn( + (hostname, _fqdn, _) = util.get_hostname_fqdn( init.cfg, cloud, metadata_only=True ) if hostname: # meta-data or user-data hostname content |