From e754db5fbd3fd475dfbe0869238b84ba200b7d15 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 10 Apr 2025 18:22:41 +0200 Subject: [PATCH] Consolidate hosts template For alpine, debian, ceph and proxmox roles. Add the union of IPv6 LL host entries across all distros to make sure nothing croaks. --- roles/alpine/templates/hosts.j2 | 2 -- roles/ceph/templates/hosts.j2 | 10 ---------- roles/proxmox/templates/hosts.j2 | 12 ------------ templates/hosts.j2 | 15 +++++++++++++++ 4 files changed, 15 insertions(+), 24 deletions(-) delete mode 100644 roles/alpine/templates/hosts.j2 delete mode 100644 roles/ceph/templates/hosts.j2 delete mode 100644 roles/proxmox/templates/hosts.j2 create mode 100644 templates/hosts.j2 diff --git a/roles/alpine/templates/hosts.j2 b/roles/alpine/templates/hosts.j2 deleted file mode 100644 index df67400..0000000 --- a/roles/alpine/templates/hosts.j2 +++ /dev/null @@ -1,2 +0,0 @@ -127.0.0.1 {{ dns_name }} {{ dns_name | split('.') | first }} localhost.localdomain localhost -::1 localhost localhost.localdomain diff --git a/roles/ceph/templates/hosts.j2 b/roles/ceph/templates/hosts.j2 deleted file mode 100644 index 30f170b..0000000 --- a/roles/ceph/templates/hosts.j2 +++ /dev/null @@ -1,10 +0,0 @@ -127.0.0.1 localhost -::1 localhost ip6-localhost ip6-loopback -ff02::1 ip6-allnodes -ff02::2 ip6-allrouters - -{% for node in nodes %} -{% for address in node|device_address %} -{{ address.address | ipaddr('address') }} {{ node.inventory_hostname }} -{% endfor %} -{% endfor %} diff --git a/roles/proxmox/templates/hosts.j2 b/roles/proxmox/templates/hosts.j2 deleted file mode 100644 index a4ac92f..0000000 --- a/roles/proxmox/templates/hosts.j2 +++ /dev/null @@ -1,12 +0,0 @@ -127.0.0.1 localhost.localdomain localhost - -::1 ip6-localhost ip6-loopback -fe00::0 ip6-localnet -ff00::0 ip6-mcastprefix -ff02::1 ip6-allnodes -ff02::2 ip6-allrouters -ff02::3 ip6-allhosts - -{% for address in interfaces | selectattr('name', '==', 'lo') | map(attribute='ip_addresses') | first %} -{{ address.address | ipaddr('address') }} {{ address.dns_name }} {{ inventory_hostname }} -{% endfor %} diff --git a/templates/hosts.j2 b/templates/hosts.j2 new file mode 100644 index 0000000..8864201 --- /dev/null +++ b/templates/hosts.j2 @@ -0,0 +1,15 @@ +127.0.0.1 localhost +::1 localhost ip6-localhost ip6-loopback +fe00::0 ip6-localnet +ff00::0 ip6-mcastprefix +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters +ff02::3 ip6-allhosts + +{# Static entries for all nodes in the cluster or just this one if there is no cluster. #} +{% for address in nodes | default([hostvars[inventory_hostname]]) + | map(attribute='interfaces') | flatten + | map(attribute='ip_addresses') | flatten + | selectattr('dns_name') %} +{{ address.address | ipaddr('address') }} {{ address.dns_name }} {{ address.dns_name | split('.') | first }} +{% endfor %}