From d323b78c168a655c3f126098be8fad79dbc1cb2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoha=C3=AF-Eliel=20BERREBY?= Date: Mon, 6 Apr 2020 16:54:20 +0200 Subject: [PATCH] fix bogus dhcpd config - move failover peer declaration to beginning of file - set split only on primary - fix re2o-service hostname - add /etc/default/isc-dhcp-server --- network.yml | 2 +- roles/isc-dhcp-server/tasks/main.yml | 11 ++- .../templates/default/isc-dhcp-server.j2 | 18 +++++ .../templates/dhcp/dhcpd.conf.j2 | 67 ++++++++++--------- 4 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 roles/isc-dhcp-server/templates/default/isc-dhcp-server.j2 diff --git a/network.yml b/network.yml index 082df3d..f402921 100644 --- a/network.yml +++ b/network.yml @@ -22,7 +22,7 @@ service_name: dhcp service_version: master service_config: - hostname: re2o.adm.auro.re + hostname: re2o.auro.re username: service-user password: "{{ vault_serviceuser_passwd }}" roles: diff --git a/roles/isc-dhcp-server/tasks/main.yml b/roles/isc-dhcp-server/tasks/main.yml index 0004081..c227e24 100644 --- a/roles/isc-dhcp-server/tasks/main.yml +++ b/roles/isc-dhcp-server/tasks/main.yml @@ -8,14 +8,21 @@ retries: 3 until: apt_result is succeeded + +- name: Configure /etc/default/isc-dhcp-server + template: + src: default/isc-dhcp-server.j2 + dest: /etc/default/isc-dhcp-server + mode: 0644 + - name: Configure isc-dhcp-server template: src: dhcp/dhcpd.conf.j2 dest: /etc/dhcp/dhcpd.conf mode: 0600 -- name: Ensure that isc-dhcp-server is started +- name: Ensure that isc-dhcp-server is started / reloaded systemd: name: isc-dhcp-server - state: started + state: restarted enabled: true diff --git a/roles/isc-dhcp-server/templates/default/isc-dhcp-server.j2 b/roles/isc-dhcp-server/templates/default/isc-dhcp-server.j2 new file mode 100644 index 0000000..83f7cae --- /dev/null +++ b/roles/isc-dhcp-server/templates/default/isc-dhcp-server.j2 @@ -0,0 +1,18 @@ +# Defaults for isc-dhcp-server (sourced by /etc/init.d/isc-dhcp-server) + +# Path to dhcpd's config file (default: /etc/dhcp/dhcpd.conf). +#DHCPDv4_CONF=/etc/dhcp/dhcpd.conf +#DHCPDv6_CONF=/etc/dhcp/dhcpd6.conf + +# Path to dhcpd's PID file (default: /var/run/dhcpd.pid). +#DHCPDv4_PID=/var/run/dhcpd.pid +#DHCPDv6_PID=/var/run/dhcpd6.pid + +# Additional options to start dhcpd with. +# Don't use options -cf or -pf here; use DHCPD_CONF/ DHCPD_PID instead +#OPTIONS="" + +# On what interfaces should the DHCP server (dhcpd) serve DHCP requests? +# Separate multiple interfaces with spaces, e.g. "eth0 eth1". +INTERFACESv4="ens19 ens20 ens21" +INTERFACESv6="" diff --git a/roles/isc-dhcp-server/templates/dhcp/dhcpd.conf.j2 b/roles/isc-dhcp-server/templates/dhcp/dhcpd.conf.j2 index da9f4d1..1f2196e 100644 --- a/roles/isc-dhcp-server/templates/dhcp/dhcpd.conf.j2 +++ b/roles/isc-dhcp-server/templates/dhcp/dhcpd.conf.j2 @@ -28,6 +28,43 @@ authoritative; #log-facility local7; +# 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; +{% 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 { interface "ens19"; @@ -74,34 +111,4 @@ subnet 10.{{ subnet_ids.users_wifi }}.0.0 netmask 255.255.0.0 { } } -{% 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 }}; -{% 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; - split 128; - max-response-delay 30; - max-unacked-updates 10; - load balance max seconds 3; - } -{% endif %}