diff --git a/cloudinit/config/cc_update_etc_hosts.py b/cloudinit/config/cc_update_etc_hosts.py index 6ad2fca..9098c7c 100644 --- a/cloudinit/config/cc_update_etc_hosts.py +++ b/cloudinit/config/cc_update_etc_hosts.py @@ -19,6 +19,7 @@ # along with this program. If not, see . import cloudinit.util as util +from cloudinit import netinfo from cloudinit.CloudConfig import per_always import StringIO @@ -36,8 +37,14 @@ log.info("manage_etc_hosts was set, but no hostname found") return - util.render_to_file('hosts', '/etc/hosts', - {'hostname': hostname, 'fqdn': fqdn}) + params = {'hostname': hostname, 'fqdn': fqdn} + + # Add network device info to params so they can be used in the template + devs = netinfo.netdev_info() + for dev, info in devs.items(): + params['dev_' + dev] = info['addr'] + + util.render_to_file('hosts', '/etc/hosts', params) except Exception: log.warn("failed to update /etc/hosts") raise