kea_dhcp(role): update to newest fux noc version

This commit is contained in:
bitwhisker 2026-07-31 17:48:58 +02:00
commit 8d9cb0007c
Signed by: bitwhisker
SSH key fingerprint: SHA256:KybIk/tusSKao6eLGY+ILlFa1rCrzwx66/acBAcKUqE
14 changed files with 322 additions and 231 deletions

View file

@ -1,6 +1,10 @@
kea_dhcp__stork_agent:
enable: false
prometheus_only: true
---
# Set Kea group name based on distribution
kea_dhcp__service_group: "{{ '_kea' if ansible_facts['distribution'] == 'Debian' else 'kea' }}"
kea_dhcp__unit_base_name: "{{ 'isc-kea' if ansible_facts['distribution'] == 'Debian' else 'kea' }}"
kea_dhcp__unit_base_sufix: "{{ '-server' if ansible_facts['distribution'] == 'Debian' else '' }}"
kea_dhcp__version_repo: "kea-3-0"
kea_dhcp__dns_servers:
v6:
- "2a07:c481:0:4::2"
@ -8,61 +12,75 @@ kea_dhcp__dns_servers:
v4:
- "185.161.128.66"
- "185.161.128.67"
kea_dhcp__include_vars:
kea_dhcp__ntp_servers:
v4:
- "185.161.128.7"
- "185.161.128.8"
v6: "2a07:c481:0:3::7"
fqdn: ntp.z9.fux-eg.net
kea_dhcp__sntp_servers:
v6:
- "2a07:c481:0:3::7"
- "2a07:c481:0:3::8"
kea_dhcp__dhcp4:
kea_dhcp__stork_agent_defaults:
enable: false
prometheus_only: true
kea_dhcp__stork_agent: {}
kea_dhcp__dhcp4_defaults:
enable: false
interfaces: [ ]
control-sockets:
- socket-name: /var/run/kea-dhcp4-ctrl-agent.sock
- socket-name: /var/run/kea/dhcp4-ctrl-agent.sock
socket-type: unix
lease-database:
type: memfile
persist: true
option-data:
- name: "domain-name-servers"
- name: domain-name-servers
code: 6
csv-format: true
data: "{{ kea_dhcp__dns_servers.v4 | join(',') }}"
subnets:
- id: 0
subnet: nil
pools:
- pool: nil
reservations:
- ip-address: nil
hostname: beispiel.test
hw-address: "00:11:22:33:44:55"
option-data:
- name: nil,
code: nil,
csv-format: true
data: nil
kea_dhcp__dhcp6:
- name: ntp-servers
code: 42
data: "{{ kea_dhcp__ntp_servers.v4 | join(',') }}"
logging:
- name: kea-dhcp4
output-options:
- output: stdout
severity: INFO
kea_dhcp__dhcp4: {}
kea_dhcp__dhcp6_defaults:
enable: false
interfaces: [ ]
control-sockets:
- socket-name: /var/run/kea/dhcp6-ctrl-agent.sock
socket-type: unix
lease-database:
type: memfile
persist: true
control-sockets:
- socket-name: /var/run/kea-dhcp6-ctrl-agent.sock
socket-type: unix
option-data:
- name: "dns-servers"
- name: dns-servers
code: 23
csv-format: true
data: "{{ kea_dhcp__dns_servers.v6 | join(',') }}"
subnets:
- id: 0
subnet: nil
pools:
- pool: nil
reservations:
- ip-address: nil
hostname: beispiel.test
hw-address: "00:11:22:33:44:55"
option-data:
- name: nil,
code: nil,
csv-format: true
data: nil
- name: sntp-servers
code: 31
data: "{{ kea_dhcp__sntp_servers.v6 | join(',') }}"
- name: ntp-server
code: 56
- name: ntp-server-address
space: v6-ntp-server-suboptions
data: "{{ kea_dhcp__ntp_servers.v6 }}"
- name: ntp-server-fqdn
space: v6-ntp-server-suboptions
data: "{{ kea_dhcp__ntp_servers.fqdn }}"
logging:
- name: kea-dhcp6
output-options:
- output: stdout
severity: INFO
kea_dhcp__dhcp6: {}
kea_dhcp__include_vars:

View file

@ -1,29 +1,40 @@
---
- name: Systemd.daemon_reload
- name: Systemd_daemon_reload
become: true
ansible.builtin.systemd_service:
daemon_reload: true
- name: Kea_dhcp4.restarted
ansible.builtin.service:
name: kea-dhcp4
state: restarted
enabled: true
- name: Kea_dhcp6.restarted
ansible.builtin.service:
name: kea-dhcp6
state: restarted
enabled: true
- name: Kea_ctrl.restarted
ansible.builtin.systemd:
name: kea-ctrl-agent
state: restarted
enabled: true
- name: Stork_agent.restarted
- name: Kea_dhcp4.restarted_debian
listen: Kea_dhcp4.restarted
become: true
when: ansible_facts['distribution'] == 'Debian'
ansible.builtin.service:
name: isc-kea-dhcp4-server
state: restarted
enabled: true
- name: Kea_dhcp6.restarted_debian
listen: Kea_dhcp6.restarted
become: true
when: ansible_facts['distribution'] == 'Debian'
ansible.builtin.service:
name: isc-kea-dhcp6-server
state: restarted
enabled: true
- name: Kea_ctrl.restarted_debian
listen: Kea_ctrl.restarted
become: true
when: ansible_facts['distribution'] == 'Debian'
ansible.builtin.systemd:
name: isc-kea-ctrl-agent
state: restarted
enabled: true
- name: Stork_agent.restarted_debian
listen: Stork_agent.restarted
become: true
when: ansible_facts['distribution'] == 'Debian'
ansible.builtin.systemd:
name: isc-stork-agent
state: restarted

View file

@ -3,9 +3,11 @@ argument_specs:
main:
short_description: "Role for managing Kea DHCP server"
options:
kea_dhcp__stork_agent:
kea_dhcp__stork_agent_defaults:
type: "dict"
description: "Configuration for Stork Agent"
description:
- "Default configuration for Stork Agent."
- "Merged with kea_dhcp__stork_agent using combine(recursive=True)."
options:
enable:
type: "bool"
@ -13,10 +15,39 @@ argument_specs:
prometheus_only:
type: "bool"
default: true
kea_dhcp__stork_agent:
type: "dict"
description:
- "Host/group override for Stork Agent configuration."
- "Merged on top of kea_dhcp__stork_agent_defaults using combine(recursive=True)."
- "Only specify the keys you want to override."
kea_dhcp__version_repo:
type: "str"
description: "Version of Kea DHCP repository to use"
description:
- "Version of Kea DHCP repository to use."
- "The versions can be found at https://cloudsmith.io/~isc/repos/"
default: "kea-3-0"
kea_dhcp__ntp_servers:
type: "dict"
description: "Default NTP servers advertised to DHCP clients (DHCPv4 option 42, DHCPv6 option 56)."
options:
v4:
type: "list"
elements: "str"
v6:
type: "str"
fqdn:
type: "str"
kea_dhcp__sntp_servers:
type: "dict"
description: "Default SNTP servers advertised to DHCPv6 clients (option 31)."
options:
v4:
type: "list"
elements: "str"
v6:
type: "list"
elements: "str"
kea_dhcp__dns_servers:
type: "dict"
description: "Default DNS servers for DHCP clients"
@ -27,9 +58,11 @@ argument_specs:
v4:
type: "list"
elements: "str"
kea_dhcp__dhcp4:
kea_dhcp__dhcp4_defaults:
type: "dict"
description: "Configuration for DHCPv4 service"
description:
- "Default configuration for DHCPv4 service."
- "Merged with kea_dhcp__dhcp4 using combine(recursive=True)."
options:
enable:
type: "bool"
@ -37,89 +70,65 @@ argument_specs:
interfaces:
type: "list"
elements: "str"
default: [ ]
default: []
control-sockets:
type: "list"
elements: "dict"
lease-database:
type: "dict"
hooks-libraries:
type: "list"
elements: "dict"
option-data:
type: "list"
elements: "dict"
subnets:
type: "list"
elements: "dict"
options:
id:
type: "int"
subnet:
type: "str"
pools:
logging:
type: "list"
elements: "dict"
kea_dhcp__dhcp4:
type: "dict"
description:
- "Host/group override for DHCPv4 configuration."
- "Merged on top of kea_dhcp__dhcp4_defaults using combine(recursive=True)."
- "Only specify the keys you want to override."
- "See kea_dhcp__dhcp4_defaults for available options."
kea_dhcp__dhcp6_defaults:
type: "dict"
description:
- "Default configuration for DHCPv6 service."
- "Merged with kea_dhcp__dhcp6 using combine(recursive=True)."
options:
pool:
type: "str"
reservations:
enable:
type: "bool"
default: false
interfaces:
type: "list"
elements: "str"
default: []
control-sockets:
type: "list"
elements: "dict"
lease-database:
type: "dict"
hooks-libraries:
type: "list"
elements: "dict"
options:
ip-address:
type: "str"
hostname:
type: "str"
hw-address:
type: "str"
duid:
type: "str"
option-data:
type: "list"
elements: "dict"
subnets:
type: "list"
elements: "dict"
logging:
type: "list"
elements: "dict"
kea_dhcp__dhcp6:
type: "dict"
description: "Configuration for DHCPv6 service"
options:
enable:
type: "bool"
default: false
interfaces:
type: "list"
elements: "str"
default: [ ]
control-sockets:
type: "list"
elements: "dict"
lease-database:
type: "dict"
option-data:
type: "list"
elements: "dict"
subnets:
type: "list"
elements: "dict"
options:
id:
type: "int"
subnet:
type: "str"
pools:
type: "list"
elements: "dict"
options:
pool:
type: "str"
reservations:
type: "list"
elements: "dict"
options:
ip-address:
type: "str"
hostname:
type: "str"
hw-address:
type: "str"
duid:
type: "str"
option-data:
type: "list"
elements: "dict"
description:
- "Host/group override for DHCPv6 configuration."
- "Merged on top of kea_dhcp__dhcp6_defaults using combine(recursive=True)."
- "Only specify the keys you want to override."
- "See kea_dhcp__dhcp6_defaults for available options."

View file

@ -0,0 +1,21 @@
---
- name: Register isc-kea apt repository
become: true
register: kea_dhcp__repo
ansible.builtin.deb822_repository:
name: "isc-{{ kea_dhcp__version_repo }}"
uris: "https://dl.cloudsmith.io/public/isc/{{ kea_dhcp__version_repo }}/deb/debian"
suites: "{{ ansible_facts['distribution_release'] }}"
components: main
signed_by: "https://dl.cloudsmith.io/public/isc/{{ kea_dhcp__version_repo }}/gpg.key"
- name: Install Kea packages
become: true
ansible.builtin.apt:
name:
- isc-kea-dhcp4
- isc-kea-dhcp6
- isc-kea-hooks
- isc-kea-ctrl-agent
- isc-kea-admin
update_cache: "{{ kea_dhcp__repo.changed }}"

View file

@ -1,25 +0,0 @@
---
- name: Install Kea packages
become: true
when: ansible_facts['distribution'] == "Debian"
block:
- name: Install Kea dhcp4
when: kea_dhcp__dhcp4.enable
ansible.builtin.apt:
name:
- isc-kea-dhcp4
- name: Install Kea dhcp6
when: kea_dhcp__dhcp6.enable
ansible.builtin.apt:
name:
- isc-kea-dhcp6
- name: Install Kea ctrl agent
when: kea_dhcp__stork_agent.enable
ansible.builtin.apt:
name:
- isc-kea-ctrl-agent
- name: Install Kea admin
when: kea_dhcp__stork_agent.enable
ansible.builtin.apt:
name:
- isc-kea-admin

View file

@ -1,20 +1,15 @@
---
- name: Include config vars
when: kea_dhcp__include_vars != None
ansible.builtin.include_vars:
file: "{{ kea_dhcp__include_vars }}"
- name: Deploy kea-dhcp4 configuration file
become: true
when: kea_dhcp__dhcp4.enable
ansible.builtin.template:
src: kea-dhcp4.conf.jinja
src: kea-dhcp4.conf.j2
dest: /etc/kea/kea-dhcp4.conf
backup: true
owner: root
group: kea
group: "{{ kea_dhcp__service_group }}"
mode: "u=rw,g=r,o="
validate: kea-dhcp4 -T %s
validate: "/usr/sbin/kea-dhcp4 -T %s" # does not work with debian apparmor policys
notify:
- Kea_dhcp4.restarted
@ -22,13 +17,13 @@
become: true
when: kea_dhcp__dhcp6.enable
ansible.builtin.template:
src: kea-dhcp6.conf.jinja
src: kea-dhcp6.conf.j2
dest: /etc/kea/kea-dhcp6.conf
backup: true
owner: root
group: kea
group: "{{ kea_dhcp__service_group }}"
mode: "u=rw,g=r,o="
validate: kea-dhcp6 -T %s
validate: /usr/sbin/kea-dhcp6 -T %s # does not work with debian apparmor policys
notify:
- Kea_dhcp6.restarted
@ -39,9 +34,9 @@
src: kea-ctrl-agent.conf.j2
dest: /etc/kea/kea-ctrl-agent.conf
owner: root
group: kea
group: "{{ kea_dhcp__service_group }}"
mode: "u=rw,g=r,o="
validate: kea-ctrl-agent -t %s
validate: /usr/sbin/kea-ctrl-agent -t %s # does not work with debian apparmor policys
notify:
- Kea_ctrl.restarted
- Stork_agent.restarted

View file

@ -1,9 +1,20 @@
---
- name: Include config vars
when: kea_dhcp__include_vars != None
ansible.builtin.include_vars:
file: "{{ kea_dhcp__include_vars }}"
- name: Merge default vars with host_vars
ansible.builtin.set_fact:
kea_dhcp__stork_agent: "{{ kea_dhcp__stork_agent_defaults | combine(kea_dhcp__stork_agent, recursive=True) }}"
kea_dhcp__dhcp4: "{{ kea_dhcp__dhcp4_defaults | combine(kea_dhcp__dhcp4, recursive=True) }}"
kea_dhcp__dhcp6: "{{ kea_dhcp__dhcp6_defaults | combine(kea_dhcp__dhcp6, recursive=True) }}"
- name: Setup Kea DHCP
block:
- name: Install Kea on Debian
when: ansible_facts['distribution'] == "Debian"
ansible.builtin.import_tasks: install_debian.yml
ansible.builtin.import_tasks: install_debian.yaml
- name: Configure Kea
ansible.builtin.include_tasks: kea.yaml

View file

@ -1,26 +1,39 @@
---
- name: Install stork-agent
block:
- name: Install isc-stork-agent
- name: Install stork-agent on Debian
when: ansible_facts['distribution'] == "Debian"
block:
- name: Register isc-stork apt repository
become: true
register: "kea_dhcp_install_repo"
ansible.builtin.deb822_repository:
name: isc-stork
uris: https://dl.cloudsmith.io/public/isc/stork/deb/debian
suites: any-version
components: main
signed_by: https://dl.cloudsmith.io/public/isc/stork/gpg.key
- name: Install isc-stork-agent
become: true
ansible.builtin.apt:
name: isc-stork-agent
update_cache: "{{ kea_dhcp_install_repo.changed }}"
- name: Add stork-agent user to _kea group on Debian
- name: Add stork-agent user to kea group on Debian
when: ansible_facts['distribution'] == "Debian"
become: true
ansible.builtin.user:
name: stork-agent
groups: [ "_kea" ]
groups: [ "{{ kea_dhcp__service_group }}" ]
append: true
- name: Config for stork-agent
ansible.builtin.template:
src: stork-agent.env.jinja
src: stork-agent.env.j2
dest: /etc/stork/agent.env
owner: root
group: root
group: "{{ kea_dhcp__service_group }}"
mode: "0660"
notify:
- Systemd_daemon_reload

View file

@ -0,0 +1,32 @@
{
"Dhcp4": {
"interfaces-config": {
"interfaces": {{ kea_dhcp__dhcp4.interfaces | to_nice_json | indent(12) }}
},
"control-sockets": {{ kea_dhcp__dhcp4['control-sockets'] | to_nice_json | indent(8) }},
"lease-database": {{ kea_dhcp__dhcp4['lease-database'] | to_nice_json | indent(8) }},
{% if kea_dhcp__dhcp4['hooks-libraries'] is defined and kea_dhcp__dhcp4['hooks-libraries'] %}
"hooks-libraries": {{ kea_dhcp__dhcp4['hooks-libraries'] | to_nice_json | indent(8) }},
{% endif %}
{% if kea_dhcp__dhcp4['option-data'] is defined and kea_dhcp__dhcp4['option-data'] %}
"option-data": {{ kea_dhcp__dhcp4['option-data'] | to_nice_json | indent(8) }},
{% endif %}
"loggers": {{ kea_dhcp__dhcp4['logging'] | to_nice_json | indent(8) }},
"subnet4": [
{% for subnet in kea_dhcp__dhcp4.subnets %}
{
"id": {{ subnet.id }},
"subnet": "{{ subnet.subnet }}",
"pools": {{ subnet.pools | to_nice_json | indent(16) }},
{% if subnet.reservations is defined and subnet.reservations %}
"reservations": {{ subnet.reservations | to_nice_json | indent(16) }},
{% endif %}
{% if subnet['option-data'] is defined and subnet['option-data'] %}
"option-data": {{ subnet['option-data'] | to_nice_json | indent(16) }}
{% endif %}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
}

View file

@ -1,27 +0,0 @@
{
"Dhcp4": {
"interfaces-config": {
"interfaces": {{ kea_dhcp__dhcp4.interfaces | to_nice_json }}
},
"control-sockets": {{ kea_dhcp__dhcp4['control-sockets'] | to_nice_json }},
"lease-database": {{ kea_dhcp__dhcp4['lease-database'] | to_nice_json }},
{% if kea_dhcp__dhcp4['option-data'] is defined and kea_dhcp__dhcp4['option-data'] %}
"option-data": {{ kea_dhcp__dhcp4['option-data'] | to_nice_json }},
{% endif %}
"subnet4": [
{% for subnet in kea_dhcp__dhcp4.subnets %}
{
"id": {{ subnet.id }},
"subnet": "{{ subnet.subnet }}",
"pools": {{ subnet.pools | to_nice_json }},
{% if subnet.reservations is defined and subnet.reservations %}
"reservations": {{ subnet.reservations | to_nice_json }},
{% endif %}
{% if subnet['option-data'] is defined and subnet['option-data'] %}
"option-data": {{ subnet['option-data'] | to_nice_json }}
{% endif %}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
}

View file

@ -0,0 +1,36 @@
{
"Dhcp6": {
"interfaces-config": {
"interfaces": {{ kea_dhcp__dhcp6.interfaces | to_nice_json | indent(12) }}
},
"control-sockets": {{ kea_dhcp__dhcp6['control-sockets'] | to_nice_json | indent(8) }},
"lease-database": {{ kea_dhcp__dhcp6['lease-database'] | to_nice_json | indent(8) }},
{% if kea_dhcp__dhcp6['hooks-libraries'] is defined and kea_dhcp__dhcp6['hooks-libraries'] %}
"hooks-libraries": {{ kea_dhcp__dhcp6['hooks-libraries'] | to_nice_json | indent(8) }},
{% endif %}
{% if kea_dhcp__dhcp6['option-data'] is defined and kea_dhcp__dhcp6['option-data'] %}
"option-data": {{ kea_dhcp__dhcp6['option-data'] | to_nice_json | indent(8) }},
{% endif %}
"loggers": {{ kea_dhcp__dhcp6['logging'] | to_nice_json | indent(8) }}{% if kea_dhcp__dhcp6.subnets is defined and kea_dhcp__dhcp6.subnets %},{% endif %}
{% if kea_dhcp__dhcp6.subnets is defined and kea_dhcp__dhcp6.subnets %}
"subnet6": [
{% for subnet in kea_dhcp__dhcp6.subnets %}
{
"id": {{ subnet.id }},
"subnet": "{{ subnet.subnet }}",
"interface": "{{ subnet.interface }}",
"allocator": "{{ subnet.allocator | default("iterative") }}",
"pools": {{ subnet.pools | to_nice_json | indent(16) }},
{% if subnet.reservations is defined and subnet.reservations %}
"reservations": {{ subnet.reservations | to_nice_json | indent(16) }},
{% endif %}
{% if subnet['option-data'] is defined and subnet['option-data'] %}
"option-data": {{ subnet['option-data'] | to_nice_json | indent(16) }}
{% endif %}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
{% endif %}
}
}

View file

@ -1,27 +0,0 @@
{
"Dhcp6": {
"interfaces-config": {
"interfaces": {{ kea_dhcp__dhcp6.interfaces | to_nice_json }}
},
"control-sockets": {{ kea_dhcp__dhcp6['control-sockets'] | to_nice_json }},
"lease-database": {{ kea_dhcp__dhcp6['lease-database'] | to_nice_json }},
{% if kea_dhcp__dhcp6['option-data'] is defined and kea_dhcp__dhcp6['option-data'] %}
"option-data": {{ kea_dhcp__dhcp6['option-data'] | to_nice_json }},
{% endif %}
"subnet6": [
{% for subnet in kea_dhcp__dhcp6.subnets %}
{
"id": {{ subnet.id }},
"subnet": "{{ subnet.subnet }}",
"pools": {{ subnet.pools | to_nice_json }},
{% if subnet.reservations is defined and subnet.reservations %}
"reservations": {{ subnet.reservations | to_nice_json }},
{% endif %}
{% if subnet['option-data'] is defined and subnet['option-data'] %}
"option-data": {{ subnet['option-data'] | to_nice_json }}
{% endif %}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
}

View file

@ -0,0 +1,44 @@
### the IP or hostname to listen on for incoming Stork server connections
# STORK_AGENT_HOST=
### the TCP port to listen on for incoming Stork server connections
# STORK_AGENT_PORT=8081
### listen for commands from the Stork server only, but not for Prometheus requests
# STORK_AGENT_LISTEN_STORK_ONLY=true
{% if kea_dhcp__stork_agent.prometheus_only %}
### listen for Prometheus requests only, but not for commands from the Stork server
STORK_AGENT_LISTEN_PROMETHEUS_ONLY=true
{% endif %}
### settings for exporting stats to Prometheus
### the IP or hostname on which the agent exports Kea statistics to Prometheus
# STORK_AGENT_PROMETHEUS_KEA_EXPORTER_ADDRESS=
### the port on which the agent exports Kea statistics to Prometheus
# STORK_AGENT_PROMETHEUS_KEA_EXPORTER_PORT=
## enable or disable collecting per-subnet stats from Kea
# STORK_AGENT_PROMETHEUS_KEA_EXPORTER_PER_SUBNET_STATS=true
### the IP or hostname on which the agent exports BIND 9 statistics to Prometheus
# STORK_AGENT_PROMETHEUS_BIND9_EXPORTER_ADDRESS=
### the port on which the agent exports BIND 9 statistics to Prometheus
# STORK_AGENT_PROMETHEUS_BIND9_EXPORTER_PORT=
### Stork Server URL used by the agent to send REST commands to the server during agent registration
# STORK_AGENT_SERVER_URL=
### skip TLS certificate verification when the Stork Agent connects
### to Kea over TLS and Kea uses self-signed certificates
# STORK_AGENT_SKIP_TLS_CERT_VERIFICATION=true
### Logging parameters
### Set logging level. Supported values are: DEBUG, INFO, WARN, ERROR
STORK_LOG_LEVEL=DEBUG
### disable output colorization
# CLICOLOR=false
### path to the hook directory
# STORK_AGENT_HOOK_DIRECTORY=

View file

@ -1,20 +0,0 @@
### Stork Agent env file
### (created and managed by ansible kea_dhcp role)
{% if kea_dhcp__stork_agent.prometheus_only %}
### listen for Prometheus requests only, but not for commands from the Stork server
STORK_AGENT_LISTEN_PROMETHEUS_ONLY=true
{% endif %}
### settings for exporting stats to Prometheus
### the IP or hostname on which the agent exports Kea statistics to Prometheus
STORK_AGENT_PROMETHEUS_KEA_EXPORTER_ADDRESS=localhost
### the port on which the agent exports Kea statistics to Prometheus
# STORK_AGENT_PROMETHEUS_KEA_EXPORTER_PORT=
### Logging parameters
### Set logging level. Supported values are: DEBUG, INFO, WARN, ERROR
STORK_LOG_LEVEL=DEBUG