From: David Galloway Date: Thu, 2 Apr 2020 15:25:03 +0000 (-0400) Subject: dhcp-server: Only create host declaration if its IP is in subnet we're writing X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e6ec246b4f671193ebb0cd11b3780b5b112769d5;p=ceph-cm-ansible.git 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 --- 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 %}