diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-12-19 22:39:01 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-12-19 22:39:01 -0500 |
commit | e75dc94a288ecec8f6096658b96c1d1154ce0bdd (patch) | |
tree | 792936e1435b9834600ae7289e1695e17ca5a33a /cloudinit | |
parent | 4ee421211816b9f40e09585137b42a8fcec42218 (diff) | |
download | vyos-cloud-init-e75dc94a288ecec8f6096658b96c1d1154ce0bdd.tar.gz vyos-cloud-init-e75dc94a288ecec8f6096658b96c1d1154ce0bdd.zip |
revert default handling of /etc/hosts to 0.6.1 style (Ubuntu 11.04)
The default management of /etc/hosts in 0.6.2 (Ubuntu 11.10)
was problematic for a couple different uses, and represented a change
in what was present in previous releases.
This changes the default behavior back to the way it was in 11.04/0.6.1.
It makes 'manage_etc_hosts' in cloud-config more than just a boolean.
It can now have 3 values:
* False (default): do not update /etc/hosts ever
* "localhost": manage /etc/hosts' 127.0.1.1 entry (the way it was done
in 11.10/0.6.2)
* True (or "template"): manage /etc/hosts via template file
This addresses bugs
* LP: #890501
* LP: #871966
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/CloudConfig/cc_update_etc_hosts.py | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/cloudinit/CloudConfig/cc_update_etc_hosts.py b/cloudinit/CloudConfig/cc_update_etc_hosts.py index 6012b8a3..1dc9c1e9 100644 --- a/cloudinit/CloudConfig/cc_update_etc_hosts.py +++ b/cloudinit/CloudConfig/cc_update_etc_hosts.py @@ -24,25 +24,29 @@ frequency = per_always def handle(name,cfg,cloud,log,args): ( hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud) - use_template = util.get_cfg_option_bool(cfg,"manage_etc_hosts", False) - if not use_template: - # manage_etc_hosts not true, update the 127.0.1.1 entry via update_etc_hosts - log.debug("manage_etc_hosts is not set, checking sanity of /etc/hosts") + manage_hosts = util.get_cfg_option_bool(cfg,"manage_etc_hosts", False) + if manage_hosts in ("True", "true", True, "template"): + # render from template file + try: + if not hostname: + log.info("manage_etc_hosts was set, but no hostname found") + return + + util.render_to_file('hosts', '/etc/hosts', \ + { 'hostname' : hostname, 'fqdn' : fqdn }) + except Exception as e: + log.warn("failed to update /etc/hosts") + raise + elif manage_hosts == "localhost": + log.debug("managing 127.0.1.1 in /etc/hosts") update_etc_hosts(hostname, fqdn, log) return + else: + if manage_hosts not in ("False", False): + log.warn("Unknown value for manage_etc_hosts. Assuming False") + else: + log.debug("not managing /etc/hosts") - # manage_etc_hosts is set, render from template file - try: - if not hostname: - log.info("manage_etc_hosts was set, but no hostname found") - return - - util.render_to_file('hosts', '/etc/hosts', \ - { 'hostname' : hostname, 'fqdn' : fqdn }) - - except Exception as e: - log.warn("failed to update /etc/hosts") - raise def update_etc_hosts(hostname, fqdn, log): with open('/etc/hosts', 'r') as etchosts: |