feat: Use automatic inventory

This commit is contained in:
2025-02-25 15:10:22 +01:00
parent 89a1ba95cd
commit 180fe1c26a
6 changed files with 46 additions and 21 deletions

17
templates/auto.conf.j2 Normal file
View File

@@ -0,0 +1,17 @@
# {{ ansible_managed }}
{% for host in groups[dnsmasq_ansible_group] %}
{%- set ipv4 = hostvars[host]['ansible_host'] %}
{%- set ipv6_suffix = hostvars[host]['ansible_host'] | split('.') | last %}
{%- set aliases = [host] + hostvars[host].get('dnsmasq_host_aliases', []) %}
# {{ host }}
{{ ipv4 }} {{ aliases | join(' ') }}
{% if (ipv6_suffix | int) < 10 %}
2a01:e0a:ee5:8b0::d00{{ ipv6_suffix }} {{ aliases | join(' ') }}
{% elif (ipv6_suffix | int) < 100 %}
2a01:e0a:ee5:8b0::d0{{ ipv6_suffix }} {{ aliases | join(' ') }}
{% else %}
2a01:e0a:ee5:8b0::d{{ ipv6_suffix }} {{ aliases | join(' ') }}
{% endif %}
{% endfor %}

View File

@@ -1,6 +1,17 @@
# {{ ansible_managed }}
{% for ip in item.ips %}
{% set aliases = item.get('aliases', []) %}
{{ ip }} {{ ([item.hostname] + aliases) | join(' ') }}
{% for host in groups['zone_gaia'] %}
{%- set ipv4 = hostvars[host]['ansible_host'] %}
{%- set ipv6_suffix = hostvars[host]['ansible_host'] | split('.') | last %}
{%- set aliases = [host] + hostvars[host].get('dnsmasq_host_aliases', []) %}
# {{ host }}
{{ ipv4 }} {{ aliases | join(' ') }}
{% if (ipv6_suffix | int) < 10 %}
2a01:e0a:ee5:8b0::d00{{ ipv6_suffix }} {{ aliases | join(' ') }}
{% elif (ipv6_suffix | int) < 100 %}
2a01:e0a:ee5:8b0::d0{{ ipv6_suffix }} {{ aliases | join(' ') }}
{% else %}
2a01:e0a:ee5:8b0::d{{ ipv6_suffix }} {{ aliases | join(' ') }}
{% endif %}
{% endfor %}

View File

@@ -0,0 +1,7 @@
# {{ ansible_managed }}
{% for host in group['zone_gaia'] %}
# {{ inventory_hostname }}
192.168.84.{{ proxmox_host_id }} {{ inventory_hostname }} {{ inventory_hostname_short }} {{ dnsmasq_host_aliases | join(' ') }}
2a01:cb00:131:f100::d0{{ proxmox_host_id }} {{ inventory_hostname }} {{ inventory_hostname_short }} {{ dnsmasq_host_aliases | join(' ') }}
{% endfor %}