{% for prefix in prefixes | selectattr('custom_fields.dhcp_server') | sort(attribute='vlan.name') %} {% if prefix.custom_fields.dhcp_server.address | 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 | ipaddr('address') }},{{ range.end_address | ipaddr('address') }},{{ prefix.prefix | ipaddr('netmask') }} {% endfor %} {% if prefix.custom_fields.gateway %} 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 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 }} {% endfor %} {% endfor %} {% endfor %} {% endif %} {% endfor %}