OPNsense KEA DHCP Subnets

This role manages KEA DHCPv4 subnets in OPNsense via the REST API.

Overview

This role manages KEA DHCPv4 subnets with full CRUD operations (Create, Read, Update, Delete). Subnets manage IP address ranges, DNS definition, and default gateway to give to the machine that makes the request.

What This Role Does

  1. Fetches existing subnets via /api/kea/dhcpv4/search_subnet to build a CIDR → UUID lookup

  2. For each subnet in opnsense_kea_dhcp_subnets_list:

    • Creates new subnets (CIDR not in OPNsense) via /api/kea/dhcpv4/add_subnet
    • Updates existing subnets (CIDR exists but pools, description, or DHCP options differ) via /api/kea/dhcpv4/set_subnet
  3. Deletes subnets not in the list via /api/kea/dhcpv4/del_subnet (list is source of truth)

  4. If any changes were made: reconfigures KEA service via /api/kea/service/reconfigure

  5. Displays a summary with the count of created, updated, and deleted subnets

Role Variables

VariableDescription
vault_opnsense_bjoffrey_user_api_keyOPNsense API key (from vault)
vault_opnsense_bjoffrey_user_api_secretOPNsense API secret (from vault)
opnsense_kea_dhcp_subnets_listList of subnet definitions

Subnet definition fields:

| Field | Description | |-------|----------|-------------| | subnet | Subnet CIDR | | pools | IP range | | description | Subnet description | | option_data | DHCP options (see below) |

Available DHCP options in option_data:

KeyDescription
domain_name_serversDNS server(s)
routersDefault gateway
domain_nameDomain name
ntp_serversNTP server(s)
tftp_server_nameTFTP server (PXE)

Notes

  • Subnets not in opnsense_kea_dhcp_subnets_list are deleted (list is source of truth)
  • Run opnsense_kea_dhcp_settings before this role to enable KEA DHCP
  • After creating subnets, run opnsense_kea_dhcp_reservations to add static assignments