From e6ec246b4f671193ebb0cd11b3780b5b112769d5 Mon Sep 17 00:00:00 2001 From: David Galloway Date: Thu, 2 Apr 2020 11:25:03 -0400 Subject: [PATCH] dhcp-server: Only create host declaration if its IP is in subnet we're writing In the Octo lab, we have multiple subnets with the same domain and VLAN. This is problematic because in the `dhcp_subnets` dict, we only anticipate there being one cidr. This change will let you have multiple "subnets" in `dhcp_subnets` without fiddling with the ansible inventory ipvars or macvars. Signed-off-by: David Galloway --- roles/dhcp-server/templates/dhcpd.subnet.conf.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/dhcp-server/templates/dhcpd.subnet.conf.j2 b/roles/dhcp-server/templates/dhcpd.subnet.conf.j2 index c99a9d40..331eca02 100644 --- a/roles/dhcp-server/templates/dhcpd.subnet.conf.j2 +++ b/roles/dhcp-server/templates/dhcpd.subnet.conf.j2 @@ -55,6 +55,7 @@ subnet {{ subnet_item.cidr | ipaddr('network') }} netmask {{ subnet_item.cidr | {% for host in groups['all'] | sort | unique -%} {% if hostvars[host][subnet_item.macvar] is defined -%} + {% if hostvars[host][subnet_item.ipvar] | ipaddr(subnet_item.cidr) | ipaddr('bool') -%} host {{ host.split('.')[0] }}-{{ subnet }} { {% if hostvars[host]['dhcp_next_server'] is defined -%} next-server {{ hostvars[host]['dhcp_next_server'] }}; @@ -67,6 +68,7 @@ subnet {{ subnet_item.cidr | ipaddr('network') }} netmask {{ subnet_item.cidr | fixed-address {{ hostvars[host][subnet_item.ipvar] }}; } {% endif -%} + {% endif -%} {% endfor -%} } # end subnet {% endif %} -- 2.47.3