servers/roles/dnsmasq/templates/10-ranges.conf.j2
Miha Frangež e93cdfd1dd Fix ipaddr call for new ansible
The ipaddr filter was moved to ansible.utils sometime after 2.18.
2026-01-12 21:43:08 +01:00

28 lines
1.4 KiB
Django/Jinja

{% for prefix in prefixes | selectattr('custom_fields.dhcp_server') | sort(attribute='vlan.name') %}
{% if prefix.custom_fields.dhcp_server.address | ansible.utils.ipaddr('address') == primary_ip4 %}
# {{ prefix.vlan.name }}
{% for range in prefix.custom_fields.dhcp_ranges | default([], true) %}
dhcp-range = set:{{ prefix.vlan.name }},{{ range.start_address | ansible.utils.ipaddr('address') }},{{ range.end_address | ansible.utils.ipaddr('address') }},{{ prefix.prefix | ansible.utils.ipaddr('netmask') }}
{% endfor %}
{% if prefix.custom_fields.gateway %}
dhcp-option = tag:{{ prefix.vlan.name }},option:router,{{ prefix.custom_fields.gateway.address | ansible.utils.ipaddr('address') }}
{% endif -%}
{% for host in hostvars.values() | selectattr('interfaces', 'defined') %}
{% for interface in host.interfaces | selectattr('mac_address') %}
{% for address in interface.ip_addresses
| selectattr('status.value', '==', 'dhcp')
| map(attribute='address') | map('ansible.utils.ipaddr', 'address')
| select('ansible.utils.in_network', prefix.prefix) %}
dhcp-host = {{ interface.mac_address | lower }},{{ address }},{{ interface.device.name | lower }}
{% endfor %}
{% endfor %}
{% endfor %}
{% endif %}
{% endfor %}
# custom reservations
{% for reservation in reservations | default([]) %}
dhcp-host = {{ reservation.mac | lower }},{{ reservation.ip | ansible.utils.ipaddr('address') }},{{ reservation.host | lower }}
{% endfor %}