99"""
1010Update Etc Hosts
1111----------------
12- **Summary:** update ``/etc/hosts``
12+ **Summary:** update the hosts file (usually ``/etc/hosts``)
1313
14- This module will update the contents of ``/etc/hosts`` based on the
15- hostname/fqdn specified in config. Management of ``/etc/hosts`` is controlled
16- using ``manage_etc_hosts``. If this is set to false, cloud-init will not manage
17- ``/etc/hosts`` at all. This is the default behavior.
14+ This module will update the contents of the local hosts database (hosts file;
15+ usually ``/etc/hosts``) based on the hostname/fqdn specified in config.
16+ Management of the hosts file is controlled using ``manage_etc_hosts``. If this
17+ is set to false, cloud-init will not manage the hosts file at all. This is the
18+ default behavior.
1819
19- If set to ``true`` or ``template``, cloud-init will generate ``/etc/ hosts``
20+ If set to ``true`` or ``template``, cloud-init will generate the hosts file
2021using the template located in ``/etc/cloud/templates/hosts.tmpl``. In the
2122``/etc/cloud/templates/hosts.tmpl`` template, the strings ``$hostname`` and
2223``$fqdn`` will be replaced with the hostname and fqdn respectively.
2324
2425If ``manage_etc_hosts`` is set to ``localhost``, then cloud-init will not
25- rewrite ``/etc/ hosts`` entirely, but rather will ensure that a entry for the
26- fqdn with a distribution dependent ip is present in ``/etc/hosts `` (i.e.
27- ``ping <hostname>`` will ping ``127.0.0.1`` or ``127.0.1.1`` or other ip).
26+ rewrite the hosts file entirely, but rather will ensure that a entry for the
27+ fqdn with a distribution dependent ip is present (i.e. ``ping <hostname> `` will
28+ ping ``127.0.0.1`` or ``127.0.1.1`` or other ip).
2829
2930.. note::
3031 if ``manage_etc_hosts`` is set ``true`` or ``template``, the contents
31- of ``/etc/ hosts`` will be updated every boot. to make any changes to
32- ``/etc/ hosts`` persistant they must be made in
32+ of the hosts file will be updated every boot. To make any changes to
33+ the hosts file persistent they must be made in
3334 ``/etc/cloud/templates/hosts.tmpl``
3435
3536.. note::
5960
6061def handle (name , cfg , cloud , log , _args ):
6162 manage_hosts = util .get_cfg_option_str (cfg , "manage_etc_hosts" , False )
63+
64+ hosts_fn = cloud .distro .hosts_fn
65+
6266 if util .translate_bool (manage_hosts , addons = ['template' ]):
6367 (hostname , fqdn ) = util .get_hostname_fqdn (cfg , cloud )
6468 if not hostname :
@@ -74,7 +78,7 @@ def handle(name, cfg, cloud, log, _args):
7478 " found for distro %s" ) %
7579 (cloud .distro .osfamily ))
7680
77- templater .render_to_file (tpl_fn_name , '/etc/hosts' ,
81+ templater .render_to_file (tpl_fn_name , hosts_fn ,
7882 {'hostname' : hostname , 'fqdn' : fqdn })
7983
8084 elif manage_hosts == "localhost" :
@@ -84,10 +88,10 @@ def handle(name, cfg, cloud, log, _args):
8488 " but no hostname was found" ))
8589 return
8690
87- log .debug ("Managing localhost in /etc/hosts" )
91+ log .debug ("Managing localhost in %s" , hosts_fn )
8892 cloud .distro .update_etc_hosts (hostname , fqdn )
8993 else :
9094 log .debug (("Configuration option 'manage_etc_hosts' is not set,"
91- " not managing /etc/hosts in module %s" ), name )
95+ " not managing %s in module %s" ), hosts_fn , name )
9296
9397# vi: ts=4 expandtab
0 commit comments