diff --git a/roles/isc-dhcp-server/tasks/main.yml b/roles/isc-dhcp-server/tasks/main.yml index c227e24..171d782 100644 --- a/roles/isc-dhcp-server/tasks/main.yml +++ b/roles/isc-dhcp-server/tasks/main.yml @@ -15,7 +15,15 @@ dest: /etc/default/isc-dhcp-server mode: 0644 -- name: Configure isc-dhcp-server + +- name: Configure dhcp-failover.conf + template: + src: dhcp/dhcp-failover.conf.j2 + dest: /etc/dhcp/dhcp-failover.conf + mode: 0600 + when: dhcp_failover is defined + +- name: Configure dhcpd.conf template: src: dhcp/dhcpd.conf.j2 dest: /etc/dhcp/dhcpd.conf diff --git a/roles/isc-dhcp-server/templates/dhcp/dhcp-failover.conf.j2 b/roles/isc-dhcp-server/templates/dhcp/dhcp-failover.conf.j2 new file mode 100644 index 0000000..6252343 --- /dev/null +++ b/roles/isc-dhcp-server/templates/dhcp/dhcp-failover.conf.j2 @@ -0,0 +1,31 @@ +failover peer "dhcp-failover" { +{% if inventory_hostname == dhcp_failover.primary_host %} + primary; + + # MCLT = Maximum Client Lead Time. + # Must be specified on the primary, forbidden on the secondary. + mclt 3600; + + # Address or DNS name on which this node listens for connections + # from its failover peer. + address {{ dhcp_failover.primary_host }}; + peer address {{ dhcp_failover.secondary_host }}; + + # Load balancing. + split 128; +{% endif %} +{% if inventory_hostname == dhcp_failover.secondary_host %} + secondary; + # Address and peer address are reversed on the secondary node. + address {{ dhcp_failover.secondary_host }}; + peer address {{ dhcp_failover.primary_host }}; +{% endif %} + + # The following options can be shared between primary and + # secondary failover peers. + port 647; + peer port 647; + max-response-delay 30; + max-unacked-updates 10; + load balance max seconds 3; +} diff --git a/roles/isc-dhcp-server/templates/dhcp/dhcpd.conf.j2 b/roles/isc-dhcp-server/templates/dhcp/dhcpd.conf.j2 index 1f2196e..01b0a8d 100644 --- a/roles/isc-dhcp-server/templates/dhcp/dhcpd.conf.j2 +++ b/roles/isc-dhcp-server/templates/dhcp/dhcpd.conf.j2 @@ -30,40 +30,8 @@ authoritative; # TODO: move this failover peer declaration to a separate file and include it. {% if dhcp_failover is defined %} -failover peer "dhcp-failover" { -{% if inventory_hostname == dhcp_failover.primary_host %} - primary; - - # MCLT = Maximum Client Lead Time. - # Must be specified on the primary, forbidden on the secondary. - mclt 3600; - - # Address or DNS name on which this node listens for connections - # from its failover peer. - address {{ dhcp_failover.primary_host }}; - peer address {{ dhcp_failover.secondary_host }}; - - # Load balancing. - split 128; +include "/etc/dhcp/dhcp-failover.conf"; {% endif %} -{% if inventory_hostname == dhcp_failover.secondary_host %} - secondary; - # Address and peer address are reversed on the secondary node. - address {{ dhcp_failover.secondary_host }}; - peer address {{ dhcp_failover.primary_host }}; -{% endif %} - - # The following options can be shared between primary and - # secondary failover peers. - port 647; - peer port 647; - max-response-delay 30; - max-unacked-updates 10; - load balance max seconds 3; - } -{% endif %} - - # Bornes WiFi subnet 10.{{ subnet_ids.ap }}.0.0 netmask 255.255.0.0 {