Initial commit
This commit is contained in:
5
ansible/roles/isc-dhcp/handlers/main.yml
Normal file
5
ansible/roles/isc-dhcp/handlers/main.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: restart isc-dhcp
|
||||
systemd:
|
||||
name: isc-dhcp-server
|
||||
state: restarted
|
||||
48
ansible/roles/isc-dhcp/tasks/main.yml
Normal file
48
ansible/roles/isc-dhcp/tasks/main.yml
Normal file
@@ -0,0 +1,48 @@
|
||||
---
|
||||
- name: Install ISC DHCP server
|
||||
apt:
|
||||
name: isc-dhcp-server
|
||||
state: present
|
||||
|
||||
- name: Stop and disable dnsmasq (conflicts with ISC DHCP)
|
||||
systemd:
|
||||
name: dnsmasq
|
||||
state: stopped
|
||||
enabled: no
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Configure ISC DHCP server defaults
|
||||
template:
|
||||
src: isc-dhcp-server.j2
|
||||
dest: /etc/default/isc-dhcp-server
|
||||
mode: '0644'
|
||||
notify: restart isc-dhcp
|
||||
|
||||
- name: Get failover peer IP
|
||||
set_fact:
|
||||
failover_peer_ip: "{{ hostvars[item].gateway_config.wg_ip }}"
|
||||
loop: "{{ groups['lab_gateways'] }}"
|
||||
when:
|
||||
- hostvars[item].gateway_config.lab_name == gateway_config.lab_name
|
||||
- hostvars[item].gateway_config.dhcp_role in ['primary', 'secondary']
|
||||
- hostvars[item].gateway_config.dhcp_role != gateway_config.dhcp_role
|
||||
register: peer_search
|
||||
|
||||
- name: Set failover peer IP from search
|
||||
set_fact:
|
||||
failover_peer_ip: "{{ peer_search.results | selectattr('ansible_facts', 'defined') | map(attribute='ansible_facts.failover_peer_ip') | first }}"
|
||||
when: peer_search.results | selectattr('ansible_facts', 'defined') | list | length > 0
|
||||
|
||||
- name: Configure DHCP failover
|
||||
template:
|
||||
src: dhcpd.conf.j2
|
||||
dest: /etc/dhcp/dhcpd.conf
|
||||
mode: '0644'
|
||||
validate: 'dhcpd -t -cf %s'
|
||||
notify: restart isc-dhcp
|
||||
|
||||
- name: Ensure ISC DHCP is enabled and started
|
||||
systemd:
|
||||
name: isc-dhcp-server
|
||||
enabled: yes
|
||||
state: started
|
||||
56
ansible/roles/isc-dhcp/templates/dhcpd.conf.j2
Normal file
56
ansible/roles/isc-dhcp/templates/dhcpd.conf.j2
Normal file
@@ -0,0 +1,56 @@
|
||||
# ISC DHCP Configuration for {{ gateway_config.lab_name }}
|
||||
# Generated by Ansible
|
||||
|
||||
authoritative;
|
||||
ddns-update-style none;
|
||||
default-lease-time 43200; # 12 hours
|
||||
max-lease-time 86400; # 24 hours
|
||||
|
||||
# Failover configuration
|
||||
{% if gateway_config.dhcp_role == 'primary' %}
|
||||
failover peer "{{ gateway_config.lab_name }}-failover" {
|
||||
primary;
|
||||
address {{ gateway_config.wg_ip }};
|
||||
port 647;
|
||||
peer address {{ failover_peer_ip }};
|
||||
peer port 647;
|
||||
max-response-delay {{ isc_dhcp_failover.max_response_delay }};
|
||||
max-unacked-updates {{ isc_dhcp_failover.max_unacked_updates }};
|
||||
mclt {{ isc_dhcp_failover.mclt }};
|
||||
split {{ isc_dhcp_failover.split }};
|
||||
load balance max seconds {{ isc_dhcp_failover.load_balance_max_seconds }};
|
||||
}
|
||||
{% elif gateway_config.dhcp_role == 'secondary' %}
|
||||
failover peer "{{ gateway_config.lab_name }}-failover" {
|
||||
secondary;
|
||||
address {{ gateway_config.wg_ip }};
|
||||
port 647;
|
||||
peer address {{ failover_peer_ip }};
|
||||
peer port 647;
|
||||
max-response-delay {{ isc_dhcp_failover.max_response_delay }};
|
||||
max-unacked-updates {{ isc_dhcp_failover.max_unacked_updates }};
|
||||
load balance max seconds {{ isc_dhcp_failover.load_balance_max_seconds }};
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
# Subnet declaration
|
||||
subnet {{ gateway_config.subnet | ipaddr('network') }} netmask {{ gateway_config.subnet | ipaddr('netmask') }} {
|
||||
option routers {{ gateway_config.subnet | ipaddr('1') | ipaddr('address') }};
|
||||
option domain-name-servers {{ gateway_config.subnet | ipaddr('1') | ipaddr('address') }};
|
||||
option domain-name "{{ gateway_config.lab_name }}.lab";
|
||||
|
||||
{% if gateway_config.dhcp_role in ['primary', 'secondary'] %}
|
||||
pool {
|
||||
failover peer "{{ gateway_config.lab_name }}-failover";
|
||||
range {{ gateway_config.subnet | ipaddr('10') | ipaddr('address') }} {{ gateway_config.subnet | ipaddr('245') | ipaddr('address') }};
|
||||
}
|
||||
{% else %}
|
||||
# Backup server - only serves when primary/secondary unavailable
|
||||
pool {
|
||||
range {{ gateway_config.subnet | ipaddr('10') | ipaddr('address') }} {{ gateway_config.subnet | ipaddr('245') | ipaddr('address') }};
|
||||
}
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
# Logging
|
||||
log-facility local7;
|
||||
10
ansible/roles/isc-dhcp/templates/isc-dhcp-server.j2
Normal file
10
ansible/roles/isc-dhcp/templates/isc-dhcp-server.j2
Normal file
@@ -0,0 +1,10 @@
|
||||
# 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
|
||||
|
||||
# Path to dhcpd's PID file (default: /var/run/dhcpd.pid).
|
||||
DHCPDv4_PID=/var/run/dhcpd.pid
|
||||
|
||||
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
|
||||
INTERFACESv4="br-{{ gateway_config.lab_name }}"
|
||||
Reference in New Issue
Block a user