diff --git a/defaults/main.yml b/defaults/main.yml index dc38b50..b5d192e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -6,7 +6,6 @@ network_reboot_enabled: True network_restart_enabled: True network_ipv6_enabled: True -network_defaultif: eth0 network_interfaces: {} # @var network_interfaces:example: > # network_interfaces: diff --git a/templates/etc/hosts.j2 b/templates/etc/hosts.j2 index ece3526..b3a015a 100644 --- a/templates/etc/hosts.j2 +++ b/templates/etc/hosts.j2 @@ -4,8 +4,11 @@ {% if network_ipv6_enabled %} ::1 localhost6 localhost6.localdomain6 {% endif %} -{% if network_hostname is defined and network_fqdn is defined and network_defaultif is defined %} -{{ network_interfaces[network_defaultif].ipaddr | default(hostvars[inventory_hostname]["ansible_" + network_defaultif].ipv4.address) }} {{ network_fqdn }} {{ network_hostname }} +{% if network_hostname is defined and network_fqdn is defined %} +{{ network_interfaces.0.ipaddr | default(ansible_default_ipv4.address) }} {{ network_fqdn }} {{ network_hostname }} +{% if network_ipv6_enabled %} +{{ network_interfaces.0.ipv6addr | default(ansible_default_ipv6.address) }} {{ network_fqdn }} {{ network_hostname }} +{% endif %} {% endif %} {% if network_hosts_extra %} {% for item in network_hosts_extra %}