From 5d07c46d2d5d73fc6c6292b4275e2dcea7cf068e Mon Sep 17 00:00:00 2001 From: Catherine Redfield Date: Thu, 10 Aug 2023 11:03:26 -0400 Subject: [PATCH 1/9] feat: check for preserve_etchostname_status key before writing /etc/hostname Some users would like to be able to bring up their systems without automatically creating /etc/hostname if it does not exist already. On distros with systemd, the hostname/hostnamectl command can be used to set the hostname transiently (which does not create /etc/hostname). To support this without changing previous behavior (that cloud-init will set the hostname statically and create /etc/hostname if it does not already exist), this change proposes a new key preserve_etchostname_state which is true, sets the hostname transiently and if not present or False, sets it statically. This change does not effect BSD or OpenBSD (or any distros that inherit their _write_hostname), as their hostname management does not use an /etc/hostname file. --- cloudinit/distros/alpine.py | 8 +++++++- cloudinit/distros/arch.py | 8 +++++++- cloudinit/distros/debian.py | 8 +++++++- cloudinit/distros/gentoo.py | 8 +++++++- cloudinit/distros/opensuse.py | 20 ++++++++++++++++++-- cloudinit/distros/photon.py | 18 ++++++++++++++++-- cloudinit/distros/rhel.py | 15 ++++++++++++++- 7 files changed, 76 insertions(+), 9 deletions(-) diff --git a/cloudinit/distros/alpine.py b/cloudinit/distros/alpine.py index eaf1fc751a8..fdc33b080f3 100644 --- a/cloudinit/distros/alpine.py +++ b/cloudinit/distros/alpine.py @@ -81,7 +81,13 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - pass + preserve_state = util.get_cfg_option_bool( + self._cfg, "preserve_etchostname_state" + ) + if not preserve_state: + pass + else: + return if not conf: conf = HostnameConf("") conf.set_hostname(hostname) diff --git a/cloudinit/distros/arch.py b/cloudinit/distros/arch.py index 2d5cfbf6573..4ac8cc5b5d0 100644 --- a/cloudinit/distros/arch.py +++ b/cloudinit/distros/arch.py @@ -119,7 +119,13 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - pass + preserve_state = util.get_cfg_option_bool( + self._cfg, "preserve_etchostname_state" + ) + if not preserve_state: + pass + else: + return if not conf: conf = HostnameConf("") conf.set_hostname(hostname) diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py index 37267559a4b..de75661c811 100644 --- a/cloudinit/distros/debian.py +++ b/cloudinit/distros/debian.py @@ -148,7 +148,13 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - pass + preserve_state = util.get_cfg_option_bool( + self._cfg, "preserve_etchostname_state" + ) + if not preserve_state: + pass + else: + return if not conf: conf = HostnameConf("") conf.set_hostname(hostname) diff --git a/cloudinit/distros/gentoo.py b/cloudinit/distros/gentoo.py index 37217fe4332..3f8e2ea857d 100644 --- a/cloudinit/distros/gentoo.py +++ b/cloudinit/distros/gentoo.py @@ -183,7 +183,13 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - pass + preserve_state = util.get_cfg_option_bool( + self._cfg, "preserve_etchostname_state" + ) + if not preserve_state: + pass + else: + return if not conf: conf = HostnameConf("") diff --git a/cloudinit/distros/opensuse.py b/cloudinit/distros/opensuse.py index 38307c9134f..9033cbe028e 100644 --- a/cloudinit/distros/opensuse.py +++ b/cloudinit/distros/opensuse.py @@ -221,10 +221,23 @@ def _set_update_method(self): self.update_method = "zypper" def _write_hostname(self, hostname, filename): + preserve_state = util.get_cfg_option_bool( + self._cfg, "preserve_etchostname_state" + ) if self.uses_systemd() and filename.endswith("/previous-hostname"): util.write_file(filename, hostname) elif self.uses_systemd(): - subp.subp(["hostnamectl", "set-hostname", str(hostname)]) + if not preserve_state: + subp.subp(["hostnamectl", "set-hostname", str(hostname)]) + else: + subp.subp( + [ + "hostnamectl", + "set-hostname", + "--transient", + str(hostname), + ] + ) else: conf = None try: @@ -232,7 +245,10 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - pass + if not preserve_state: + pass + else: + return if not conf: conf = HostnameConf("") conf.set_hostname(hostname) diff --git a/cloudinit/distros/photon.py b/cloudinit/distros/photon.py index 14cefe90f27..ef611fce081 100644 --- a/cloudinit/distros/photon.py +++ b/cloudinit/distros/photon.py @@ -93,9 +93,23 @@ def _write_hostname(self, hostname, filename): if filename and filename.endswith("/previous-hostname"): util.write_file(filename, hostname) else: - ret, _out, err = self.exec_cmd( - ["hostnamectl", "set-hostname", str(hostname)] + ret = None + preserve_state = util.get_cfg_option_bool( + self._cfg, "preserve_etchostname_state" ) + if not preserve_state: + ret, _out, err = self.exec_cmd( + ["hostnamectl", "set-hostname", str(hostname)] + ) + else: + ret, _out, err = self.exec_cmd( + [ + "hostnamectl", + "set-hostname", + "--transient", + str(hostname), + ] + ) if ret: LOG.warning( ( diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py index 644422a748a..0a9c79d060b 100644 --- a/cloudinit/distros/rhel.py +++ b/cloudinit/distros/rhel.py @@ -109,7 +109,20 @@ def _write_hostname(self, hostname, filename): conf.set_hostname(hostname) util.write_file(filename, str(conf), 0o644) elif self.uses_systemd(): - subp.subp(["hostnamectl", "set-hostname", str(hostname)]) + preserve_state = util.get_cfg_option_bool( + self._cfg, "preserve_etchostname_state" + ) + if not preserve_state: + subp.subp(["hostnamectl", "set-hostname", str(hostname)]) + else: + subp.subp( + [ + "hostnamectl", + "set-hostname", + "--transient", + str(hostname), + ] + ) else: host_cfg = { "HOSTNAME": hostname, From 8819bc146be788f23ba399b6d1acdef36abea530 Mon Sep 17 00:00:00 2001 From: Catherine Redfield Date: Mon, 14 Aug 2023 15:58:35 -0400 Subject: [PATCH 2/9] chore: add catmredto cla signers --- tools/.github-cla-signers | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers index 7f2f2744a1a..abac0f2e8db 100644 --- a/tools/.github-cla-signers +++ b/tools/.github-cla-signers @@ -25,6 +25,7 @@ bmhughes brianphaley CalvoM candlerb +catmsred cawamata cclauss chifac08 From 904b17470b5c4f5be7c7b5ab98284753bd490e25 Mon Sep 17 00:00:00 2001 From: Catherine Redfield Date: Thu, 24 Aug 2023 12:28:56 -0400 Subject: [PATCH 3/9] feat: update key name to create_hostname_file Changed the key name for creating the hostname file if it does not exist to create_hostname_file since that is more intuitive the the previously proposed preserve_hostname_state. This commit still excludes BSD instances. --- cloudinit/distros/alpine.py | 6 +++--- cloudinit/distros/arch.py | 6 +++--- cloudinit/distros/debian.py | 6 +++--- cloudinit/distros/gentoo.py | 6 +++--- cloudinit/distros/opensuse.py | 2 +- cloudinit/distros/photon.py | 6 +++--- cloudinit/distros/rhel.py | 6 +++--- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cloudinit/distros/alpine.py b/cloudinit/distros/alpine.py index fdc33b080f3..cf08e2f414b 100644 --- a/cloudinit/distros/alpine.py +++ b/cloudinit/distros/alpine.py @@ -81,10 +81,10 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - preserve_state = util.get_cfg_option_bool( - self._cfg, "preserve_etchostname_state" + create_hostname_file = util.get_cfg_option_bool( + self._cfg, "create_hostname_file", True ) - if not preserve_state: + if create_hostname_file: pass else: return diff --git a/cloudinit/distros/arch.py b/cloudinit/distros/arch.py index 4ac8cc5b5d0..3da4775db28 100644 --- a/cloudinit/distros/arch.py +++ b/cloudinit/distros/arch.py @@ -119,10 +119,10 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - preserve_state = util.get_cfg_option_bool( - self._cfg, "preserve_etchostname_state" + create_hostname_file = util.get_cfg_option_bool( + self._cfg, "create_hostname_file", True ) - if not preserve_state: + if create_hostname_file: pass else: return diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py index de75661c811..90f2d5d84e1 100644 --- a/cloudinit/distros/debian.py +++ b/cloudinit/distros/debian.py @@ -148,10 +148,10 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - preserve_state = util.get_cfg_option_bool( - self._cfg, "preserve_etchostname_state" + create_hostname_file = util.get_cfg_option_bool( + self._cfg, "create_hostname_file", True ) - if not preserve_state: + if create_hostname_file: pass else: return diff --git a/cloudinit/distros/gentoo.py b/cloudinit/distros/gentoo.py index 3f8e2ea857d..48a97948374 100644 --- a/cloudinit/distros/gentoo.py +++ b/cloudinit/distros/gentoo.py @@ -183,10 +183,10 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - preserve_state = util.get_cfg_option_bool( - self._cfg, "preserve_etchostname_state" + create_hostname_file = util.get_cfg_option_bool( + self._cfg, "create_hostname_file", True ) - if not preserve_state: + if create_hostname_file: pass else: return diff --git a/cloudinit/distros/opensuse.py b/cloudinit/distros/opensuse.py index 9033cbe028e..b0ecafbd9fd 100644 --- a/cloudinit/distros/opensuse.py +++ b/cloudinit/distros/opensuse.py @@ -222,7 +222,7 @@ def _set_update_method(self): def _write_hostname(self, hostname, filename): preserve_state = util.get_cfg_option_bool( - self._cfg, "preserve_etchostname_state" + self._cfg, "create_hostname_file" ) if self.uses_systemd() and filename.endswith("/previous-hostname"): util.write_file(filename, hostname) diff --git a/cloudinit/distros/photon.py b/cloudinit/distros/photon.py index ef611fce081..1556829fbe6 100644 --- a/cloudinit/distros/photon.py +++ b/cloudinit/distros/photon.py @@ -94,10 +94,10 @@ def _write_hostname(self, hostname, filename): util.write_file(filename, hostname) else: ret = None - preserve_state = util.get_cfg_option_bool( - self._cfg, "preserve_etchostname_state" + create_hostname_file = util.get_cfg_option_bool( + self._cfg, "create_hostname_file", True ) - if not preserve_state: + if create_hostname_file: ret, _out, err = self.exec_cmd( ["hostnamectl", "set-hostname", str(hostname)] ) diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py index 0a9c79d060b..cf6b5eee522 100644 --- a/cloudinit/distros/rhel.py +++ b/cloudinit/distros/rhel.py @@ -109,10 +109,10 @@ def _write_hostname(self, hostname, filename): conf.set_hostname(hostname) util.write_file(filename, str(conf), 0o644) elif self.uses_systemd(): - preserve_state = util.get_cfg_option_bool( - self._cfg, "preserve_etchostname_state" + create_hostname_file = util.get_cfg_option_bool( + self._cfg, "create_hostname_file", True ) - if not preserve_state: + if create_hostname_file: subp.subp(["hostnamectl", "set-hostname", str(hostname)]) else: subp.subp( From 056dda03cdd9fd74589775af9171cc6e8cdae249 Mon Sep 17 00:00:00 2001 From: Catherine Redfield Date: Thu, 24 Aug 2023 12:32:52 -0400 Subject: [PATCH 4/9] feat: ensure create_hostname_file is added to distro cfg The new create_hostname_file is necessary for the distro to be aware of. This change adds create_hostname_file to the cfg distro uses when it runs cc_set_hostname and cc_update_hostname. --- cloudinit/config/cc_set_hostname.py | 7 +++++++ cloudinit/config/cc_update_hostname.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/cloudinit/config/cc_set_hostname.py b/cloudinit/config/cc_set_hostname.py index b0c84962534..5d46a7d54b0 100644 --- a/cloudinit/config/cc_set_hostname.py +++ b/cloudinit/config/cc_set_hostname.py @@ -96,6 +96,13 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: if hostname_fqdn is not None: cloud.distro.set_option("prefer_fqdn_over_hostname", hostname_fqdn) + # Set create_hostname_file in distro + create_hostname_file = util.get_cfg_option_bool( + cfg, "create_hostname_file", None + ) + if create_hostname_file is not None: + cloud.distro.set_option("create_hostname_file", create_hostname_file) + (hostname, fqdn, is_default) = util.get_hostname_fqdn(cfg, cloud) # Check for previous successful invocation of set_hostname diff --git a/cloudinit/config/cc_update_hostname.py b/cloudinit/config/cc_update_hostname.py index 8de51147971..5e12dde4c60 100644 --- a/cloudinit/config/cc_update_hostname.py +++ b/cloudinit/config/cc_update_hostname.py @@ -99,6 +99,13 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: if hostname_fqdn is not None: cloud.distro.set_option("prefer_fqdn_over_hostname", hostname_fqdn) + # Set create_hostname_file in distro + create_hostname_file = util.get_cfg_option_bool( + cfg, "create_hostname_file", None + ) + if create_hostname_file is not None: + cloud.distro.set_option("create_hostname_file", create_hostname_file) + (hostname, fqdn, is_default) = util.get_hostname_fqdn(cfg, cloud) if is_default and hostname == "localhost": # https://github.com/systemd/systemd/commit/d39079fcaa05e23540d2b1f0270fa31c22a7e9f1 From ef5ff7da85a1a9115b4f0ebe2f0bc18a49aa36d9 Mon Sep 17 00:00:00 2001 From: Catherine Redfield Date: Thu, 24 Aug 2023 12:40:19 -0400 Subject: [PATCH 5/9] test: create_hostname_file set to false in all /etc/hostname distros This config adds unit tests for all the non-BSD updated cc_set_hostname calls for the create_hostname_file being set to False (i.e. testing that the file is not created) --- .../unittests/config/test_cc_set_hostname.py | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tests/unittests/config/test_cc_set_hostname.py b/tests/unittests/config/test_cc_set_hostname.py index 7e7358e47be..35befa0040f 100644 --- a/tests/unittests/config/test_cc_set_hostname.py +++ b/tests/unittests/config/test_cc_set_hostname.py @@ -259,5 +259,95 @@ def test_ignore_empty_previous_artifact_file(self): contents = util.load_file("/etc/hostname") self.assertEqual("blah", contents.strip()) + def test_create_hostname_file_false(self): + cfg = { + "hostname": "foo", + "fqdn": "foo.blah.yahoo.com", + "create_hostname_file": False, + } + distro = self._fetch_distro("debian") + paths = helpers.Paths({"cloud_dir": self.tmp}) + ds = None + cc = cloud.Cloud(ds, paths, {}, distro, None) + self.patchUtils(self.tmp) + cc_set_hostname.handle("cc_set_hostname", cfg, cc, []) + with self.assertRaises(FileNotFoundError): + util.load_file("/etc/hostname") + + def test_create_hostname_file_false_arch(self): + cfg = { + "hostname": "foo", + "fqdn": "foo.blah.yahoo.com", + "create_hostname_file": False, + } + distro = self._fetch_distro("arch") + paths = helpers.Paths({"cloud_dir": self.tmp}) + ds = None + cc = cloud.Cloud(ds, paths, {}, distro, None) + self.patchUtils(self.tmp) + cc_set_hostname.handle("cc_set_hostname", cfg, cc, []) + with self.assertRaises(FileNotFoundError): + util.load_file("/etc/hostname") + + def test_create_hostname_file_false_alpine(self): + cfg = { + "hostname": "foo", + "fqdn": "foo.blah.yahoo.com", + "create_hostname_file": False, + } + distro = self._fetch_distro("alpine") + paths = helpers.Paths({"cloud_dir": self.tmp}) + ds = None + cc = cloud.Cloud(ds, paths, {}, distro, None) + self.patchUtils(self.tmp) + cc_set_hostname.handle("cc_set_hostname", cfg, cc, []) + with self.assertRaises(FileNotFoundError): + util.load_file("/etc/hostname") + + def test_create_hostname_file_false_gentoo(self): + cfg = { + "hostname": "foo", + "fqdn": "foo.blah.yahoo.com", + "create_hostname_file": False, + } + distro = self._fetch_distro("gentoo") + paths = helpers.Paths({"cloud_dir": self.tmp}) + ds = None + cc = cloud.Cloud(ds, paths, {}, distro, None) + self.patchUtils(self.tmp) + cc_set_hostname.handle("cc_set_hostname", cfg, cc, []) + with self.assertRaises(FileNotFoundError): + util.load_file("/etc/hostname") + + def test_create_hostname_file_false_photon(self): + cfg = { + "hostname": "foo", + "fqdn": "foo.blah.yahoo.com", + "create_hostname_file": False, + } + distro = self._fetch_distro("photon") + paths = helpers.Paths({"cloud_dir": self.tmp}) + ds = None + cc = cloud.Cloud(ds, paths, {}, distro, None) + self.patchUtils(self.tmp) + cc_set_hostname.handle("cc_set_hostname", cfg, cc, []) + with self.assertRaises(FileNotFoundError): + util.load_file("/etc/hostname") + + def test_create_hostname_file_false_rhel(self): + cfg = { + "hostname": "foo", + "fqdn": "foo.blah.yahoo.com", + "create_hostname_file": False, + } + distro = self._fetch_distro("rhel") + paths = helpers.Paths({"cloud_dir": self.tmp}) + ds = None + cc = cloud.Cloud(ds, paths, {}, distro, None) + self.patchUtils(self.tmp) + cc_set_hostname.handle("cc_set_hostname", cfg, cc, []) + with self.assertRaises(FileNotFoundError): + util.load_file("/etc/hostname") + # vi: ts=4 expandtab From b2537b576e826362514bf44967389cbc6e474659 Mon Sep 17 00:00:00 2001 From: Catherine Redfield Date: Tue, 5 Sep 2023 15:17:32 -0400 Subject: [PATCH 6/9] fix: normalize local variable name This commit normalizes the opensuse create_hostname_file variable to match the other distros. --- cloudinit/distros/opensuse.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cloudinit/distros/opensuse.py b/cloudinit/distros/opensuse.py index b0ecafbd9fd..0c84e1861af 100644 --- a/cloudinit/distros/opensuse.py +++ b/cloudinit/distros/opensuse.py @@ -221,13 +221,13 @@ def _set_update_method(self): self.update_method = "zypper" def _write_hostname(self, hostname, filename): - preserve_state = util.get_cfg_option_bool( + create_hostname_file = util.get_cfg_option_bool( self._cfg, "create_hostname_file" ) if self.uses_systemd() and filename.endswith("/previous-hostname"): util.write_file(filename, hostname) elif self.uses_systemd(): - if not preserve_state: + if not create_hostname_file: subp.subp(["hostnamectl", "set-hostname", str(hostname)]) else: subp.subp( @@ -245,7 +245,7 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - if not preserve_state: + if not create_hostname_file: pass else: return From a67aa5b61d19043dc99343732bd76548d269fd3c Mon Sep 17 00:00:00 2001 From: Catherine Redfield Date: Fri, 8 Sep 2023 09:28:01 -0400 Subject: [PATCH 7/9] doc: add create_hostname_file key to schema Add new create_hostname_file key to the schema for cc_set_hostname and cc_update_hostname so it is correctly documented. --- cloudinit/config/schemas/schema-cloud-config-v1.json | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cloudinit/config/schemas/schema-cloud-config-v1.json b/cloudinit/config/schemas/schema-cloud-config-v1.json index 79031e0835a..c0cbd98ece8 100644 --- a/cloudinit/config/schemas/schema-cloud-config-v1.json +++ b/cloudinit/config/schemas/schema-cloud-config-v1.json @@ -2576,7 +2576,12 @@ "prefer_fqdn_over_hostname": { "type": "boolean", "description": "If true, the fqdn will be used if it is set. If false, the hostname will be used. If unset, the result is distro-dependent" - } + }, + "create_hostname_file": { + "type": "boolean", + "default": false, + "description": "If false, the hostname file (e.g. /etc/hostname) will not be created if it does not exist. If true, the hostname will always be created." + } } }, "cc_set_passwords": { @@ -3064,6 +3069,11 @@ "type": "boolean", "default": null, "description": "By default, it is distro-dependent whether cloud-init uses the short hostname or fully qualified domain name when both ``local-hostname` and ``fqdn`` are both present in instance metadata. When set ``true``, use fully qualified domain name if present as hostname instead of short hostname. When set ``false``, use ``hostname`` config value if present, otherwise fallback to ``fqdn``." + }, + "create_hostname_file": { + "type": "boolean", + "default": false, + "description": "If false, the hostname file (e.g. /etc/hostname) will not be created if it does not exist. If true, the hostname will always be created." } } }, From cb3415852751e8211e7d08bffb06bfa44902beb7 Mon Sep 17 00:00:00 2001 From: Catherine Redfield Date: Mon, 11 Sep 2023 10:04:40 -0400 Subject: [PATCH 8/9] fix: correct opensuse create_hostname_file key usage When key name was updated from preserve_etc_hostname_status to create_hostname_file, the opensuse logic was not correctly updated. This commit brings opensuse into alignment with the correct create_hostname_file key logic that is implemented in other distros. --- cloudinit/distros/opensuse.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cloudinit/distros/opensuse.py b/cloudinit/distros/opensuse.py index 0c84e1861af..b8d527929fd 100644 --- a/cloudinit/distros/opensuse.py +++ b/cloudinit/distros/opensuse.py @@ -222,12 +222,12 @@ def _set_update_method(self): def _write_hostname(self, hostname, filename): create_hostname_file = util.get_cfg_option_bool( - self._cfg, "create_hostname_file" + self._cfg, "create_hostname_file", True ) if self.uses_systemd() and filename.endswith("/previous-hostname"): util.write_file(filename, hostname) elif self.uses_systemd(): - if not create_hostname_file: + if create_hostname_file: subp.subp(["hostnamectl", "set-hostname", str(hostname)]) else: subp.subp( @@ -245,7 +245,7 @@ def _write_hostname(self, hostname, filename): # so lets see if we can read it first. conf = self._read_hostname_conf(filename) except IOError: - if not create_hostname_file: + if create_hostname_file: pass else: return From e9286e20da63686f05faa53585aa012aa8e6f71f Mon Sep 17 00:00:00 2001 From: Catherine Redfield Date: Mon, 11 Sep 2023 10:07:22 -0400 Subject: [PATCH 9/9] doc: correct create_hostname_file default and expand description create_hostname_file should be true by default. This change correctly sets that value as well as expanding the description to clarify the behavior on systemd distros. --- .../config/schemas/schema-cloud-config-v1.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cloudinit/config/schemas/schema-cloud-config-v1.json b/cloudinit/config/schemas/schema-cloud-config-v1.json index c0cbd98ece8..e830808db53 100644 --- a/cloudinit/config/schemas/schema-cloud-config-v1.json +++ b/cloudinit/config/schemas/schema-cloud-config-v1.json @@ -2577,11 +2577,11 @@ "type": "boolean", "description": "If true, the fqdn will be used if it is set. If false, the hostname will be used. If unset, the result is distro-dependent" }, - "create_hostname_file": { - "type": "boolean", - "default": false, - "description": "If false, the hostname file (e.g. /etc/hostname) will not be created if it does not exist. If true, the hostname will always be created." - } + "create_hostname_file": { + "type": "boolean", + "default": true, + "description": "If ``false``, the hostname file (e.g. /etc/hostname) will not be created if it does not exist. On systems that use systemd, setting create_hostname_file to ``false`` will set the hostname transiently. If ``true``, the hostname file will always be created and the hostname will be set statically on systemd systems. Default: ``true``" + } } }, "cc_set_passwords": { @@ -3070,10 +3070,10 @@ "default": null, "description": "By default, it is distro-dependent whether cloud-init uses the short hostname or fully qualified domain name when both ``local-hostname` and ``fqdn`` are both present in instance metadata. When set ``true``, use fully qualified domain name if present as hostname instead of short hostname. When set ``false``, use ``hostname`` config value if present, otherwise fallback to ``fqdn``." }, - "create_hostname_file": { - "type": "boolean", - "default": false, - "description": "If false, the hostname file (e.g. /etc/hostname) will not be created if it does not exist. If true, the hostname will always be created." + "create_hostname_file": { + "type": "boolean", + "default": true, + "description": "If ``false``, the hostname file (e.g. /etc/hostname) will not be created if it does not exist. On systems that use systemd, setting create_hostname_file to ``false`` will set the hostname transiently. If ``true``, the hostname file will always be created and the hostname will be set statically on systemd systems. Default: ``true``" } } },