From 5c8baa80e3f5037c54ed96a3fd9fdda16190ba79 Mon Sep 17 00:00:00 2001 From: Markus Hauschild Date: Fri, 19 Apr 2024 15:10:44 +0200 Subject: [PATCH] kea: new role (replaces dhcpd) --- roles/kea/handlers/main.yml | 4 + roles/kea/tasks/main.yml | 17 +++ roles/kea/templates/kea/kea-dhcp4.conf.j2 | 155 ++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 roles/kea/handlers/main.yml create mode 100644 roles/kea/tasks/main.yml create mode 100644 roles/kea/templates/kea/kea-dhcp4.conf.j2 diff --git a/roles/kea/handlers/main.yml b/roles/kea/handlers/main.yml new file mode 100644 index 0000000..b3765c6 --- /dev/null +++ b/roles/kea/handlers/main.yml @@ -0,0 +1,4 @@ +--- + +- name: Restart kea-dhcp4-server + service: name=kea-dhcp4-server state=restarted diff --git a/roles/kea/tasks/main.yml b/roles/kea/tasks/main.yml new file mode 100644 index 0000000..8b3df6a --- /dev/null +++ b/roles/kea/tasks/main.yml @@ -0,0 +1,17 @@ +--- + +- name: Install the kea dhcp server + apt: + name: + - kea-dhcp4-server + - kea-dhcp-ddns-server + +- name: Configure the kea dhcp server + template: + src: kea/kea-dhcp4.conf.j2 + dest: /etc/kea/kea-dhcp4.conf +# validate: kea-dhcp4 -t %s + notify: Restart kea-dhcp4-server + +- name: Start the kea dhcp server + service: name=kea-dhcp4-server state=started enabled=yes diff --git a/roles/kea/templates/kea/kea-dhcp4.conf.j2 b/roles/kea/templates/kea/kea-dhcp4.conf.j2 new file mode 100644 index 0000000..982f313 --- /dev/null +++ b/roles/kea/templates/kea/kea-dhcp4.conf.j2 @@ -0,0 +1,155 @@ +{ + +"Dhcp4": { + "interfaces-config": { + "interfaces": [ "{{ ansible_default_ipv4['interface'] }}" ] + }, + + "control-socket": { + "socket-type": "unix", + "socket-name": "/run/kea/kea4-ctrl-socket" + }, + + "lease-database": { + "type": "memfile", + "lfc-interval": 3600 + }, + + "expired-leases-processing": { + "reclaim-timer-wait-time": 10, + "flush-reclaimed-timer-wait-time": 25, + "hold-reclaimed-time": 3600, + "max-reclaim-leases": 100, + "max-reclaim-time": 250, + "unwarned-reclaim-cycles": 5 + }, + + "renew-timer": 900, + "rebind-timer": 1800, + "valid-lifetime": 3600, + + "option-data": [ + { + "name": "domain-name-servers", + "data": "{{ name_servers | join(', ') }}" + }, + + { + "name": "domain-name", + "data": "binary.kitchen" + }, + + { + "name": "domain-search", + "data": "binary.kitchen" + } + ], + + "subnet4": [ + { + "subnet": "172.23.1.0/24", + + "option-data": [ + { + "name": "routers", + "data": "172.23.1.1" + } + ], + + "reservations": [ + { + "hw-address": "44:48:c1:ce:a9:00", + "ip-address": "172.23.1.41", + "hostname": "ap01" + }, + + { + "hw-address": "74:9e:75:ce:93:54", + "ip-address": "172.23.1.44", + "hostname": "ap04" + }, + + { + "hw-address": "bc:9f:e4:c3:6f:aa", + "ip-address": "172.23.1.45", + "hostname": "ap05" + }, + + { + "hw-address": "94:b4:0f:c0:1d:a0", + "ip-address": "172.23.1.46", + "hostname": "ap06" + } + ] + }, + + { + "subnet": "172.23.2.0/24", + + "option-data": [ + { + "name": "routers", + "data": "172.23.2.1" + } + ] + }, + + { + "subnet": "172.23.3.0/24", + + "pools": [ { "pool": "172.23.3.10 - 172.23.3.230" } ], + + "option-data": [ + { + "name": "routers", + "data": "172.23.3.1" + }, + + { + "name": "domain-search", + "data": "binary.kitchen, users.binary.kitchen" + } + ], + + "reservations": [ + { + "hw-address": "1a:1b:1c:1d:1e:1f", + "ip-address": "172.23.3.201", + "hostname": "special-snowflake", + "option-data": [ { + "name": "domain-name-servers", + "data": "10.1.1.202, 10.1.1.203" + } ] + } + ] + }, + + { + "subnet": "172.23.4.0/24", + + "pools": [ { "pool": "172.23.4.10 - 172.23.4.240" } ], + + "option-data": [ + { + "name": "routers", + "data": "172.23.4.1" + } + ] + } + ], + + "loggers": [ + { + "name": "kea-dhcp4", + "output_options": [ + { + "output": "stdout", + "pattern": "%-5p %m\n" + } + ], + "severity": "INFO", + "debuglevel": 0 + } + ] +} +}