diff --git a/cloudinit/config/cc_set_hostname.py b/cloudinit/config/cc_set_hostname.py index b0c849625349..5d46a7d54b0f 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 8de511479710..5e12dde4c604 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