From 8fe311094aa2109173b5d255aa2ee34ea3d85d75 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 21 Aug 2024 20:54:49 +0200 Subject: [PATCH] fix: simplify ipaddr mapping in hosts file --- defaults/main.yml | 1 - templates/etc/hosts.j2 | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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 %}