From 8276c6e8b4eaafe719bc35ac81e613fb74751384 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 6 Jan 2026 16:48:48 +0100 Subject: [PATCH] dnsmasq: allow DHCP for non-primary IP address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not actually needed but doesn’t hurt. Except it makes instantiating the template even slower. Maybe rewrite the whole thing. --- roles/dnsmasq/templates/10-ranges.conf.j2 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/roles/dnsmasq/templates/10-ranges.conf.j2 b/roles/dnsmasq/templates/10-ranges.conf.j2 index badc9ca..2d64db4 100644 --- a/roles/dnsmasq/templates/10-ranges.conf.j2 +++ b/roles/dnsmasq/templates/10-ranges.conf.j2 @@ -8,10 +8,13 @@ dhcp-range = set:{{ prefix.vlan.name }},{{ range.start_address | ipaddr('address dhcp-option = tag:{{ prefix.vlan.name }},option:router,{{ prefix.custom_fields.gateway.address | ipaddr('address') }} {% endif -%} -{% for host in hostvars.values() | selectattr('primary_ip4', 'defined') | selectattr('primary_ip4', 'ansible.utils.in_network', prefix.prefix) %} +{% 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') %} -dhcp-host = {{ interface.mac_address | lower }},{{ address.address | ipaddr('address') }},{{ interface.device.name | lower }} +{% for address in interface.ip_addresses + | selectattr('status.value', '==', 'dhcp') + | map(attribute='address') | map('ipaddr', 'address') + | select('ansible.utils.in_network', prefix.prefix) %} +dhcp-host = {{ interface.mac_address | lower }},{{ address }},{{ interface.device.name | lower }} {% endfor %} {% endfor %} {% endfor %}