From 5c4e5e9a6a893aa2fb0df50cf327e942b52995b9 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Fri, 12 Jul 2019 15:31:10 +0200 Subject: Do not try to verify the hostname config if the script is run by cloud-init. --- src/conf_mode/host_name.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/conf_mode/host_name.py b/src/conf_mode/host_name.py index eb4b339e9..1988f7b4f 100755 --- a/src/conf_mode/host_name.py +++ b/src/conf_mode/host_name.py @@ -117,6 +117,10 @@ def get_config(arguments): if conf.exists("system host-name"): hosts['hostname'] = conf.return_value("system host-name") + # This may happen if the config is not loaded yet, + # e.g. if run by cloud-init + if not hosts['hostname']: + hosts['hostname'] = default_config_data['hostname'] if conf.exists("system domain-name"): hosts['domain_name'] = conf.return_value("system domain-name") @@ -290,7 +294,12 @@ if __name__ == '__main__': try: c = get_config(args) - verify(c) + # If it's called from dhclient, then either: + # a) verification was already done at commit time + # b) it's run on an unconfigured system, e.g. by cloud-init + # Therefore, verification is either redundant or useless + if not args.dhclient: + verify(c) generate(c) apply(c) except ConfigError as e: -- cgit v1.2.3