Page MenuHomePhabricator

Manage DHCP from Netbox
Open, Needs TriagePublic


New servers provisioning currently need a Puppet commit to statically set the primary NIC's MAC/hostname/IP mapping in the DHCP config.
This takes time and is error prone. A better option would be to generate it from Netbox data.
The only data not present in Netbox is option pxelinux.pathprefix used when a host needs a different Debian version than the default one.

Physical hosts

Prerequisite is to configure DHCP option 82 (see T221388, and an example of dhcp config), this feature adds the switch interface and interface description to the DHCP request. At this point the switch port is already configured based on Netbox and enabled with Homer.

Then there are several options to configure DHCP. Feel free to add any other options or complete them.
(From a previous discussion with Riccardo)

Cron to generate the config on the install servers

Prerequisite is to add a custom field to the devices, to specify if they need a different than default option pxelinux.pathprefix.
Then have a script that runs regularly and fetch all servers with a planned status as well as a connected cable and generate the matching DHCP configuration.
Downsides are:

  • need of an extra Netbox field
  • regular querying of Netbox (slow) API
  • have to wait for the cron to run before booting the host


  • Probably the easiest to setup
  • works for multiple hosts in parallel

Generate the config on Netbox hosts and cron to pull it

Slightly similar as above, but workaround the Netbox API limitation by having the config pushed to a git repo (or fetchable via https) on the Netbox hosts.


Pass the hostname(s) and (if not default) option pxelinux.pathprefix as command line arguments.
It will then generate the relevant DHCP config and push them to the relevant install server. Maybe even run the DHCP and display its logs?
Then maybe pause until the operator continues the script and cleanup the config once done.


  • Less hard on the Netbox API
  • No need for an extra Netbox field
  • More control over what's generated
  • Can do other checks on the way (maybe


  • More complex to setup?
  • Yet another cookbook to run?
  • Might cause race conditions if several persons provision several hosts in parallel?

DHCP Hooks

Prerequisite: upgrade to ISC-DHCP to ISC-KEA, as I can't find a similar feature for ISC-DHCP.

Kea has hooks that could potentially query Netbox in real time. The risk is that Netbox takes too much time to run and the hosts DHCP request times out.


As we can sync MAC addresses from Ganeti to Netbox, the easier might be to generate a similar config as we have now (so no need of option 82).
And the sre.ganeti.makevm cookbook could take care of updating the config with either one of the choice made above (either force the cron/fetch/etc or generate/push the config directly).

Related Objects

Event Timeline

Change 662641 had a related patch set uploaded (by Ayounsi; owner: Ayounsi):
[operations/homer/public@master] Add option-82 to prod vlans

Change 662641 merged by jenkins-bot:
[operations/homer/public@master] Add option-82 to prod vlans

Mentioned in SAL (#wikimedia-operations) [2021-02-08T16:30:10Z] <XioNoX> adding option-82 to all prod vlans DHCP - T269855

Bonus thought: should it distribute v6 IPs as well? That way less hack during host bootstrapping. And it paves the way to a v6 only future.

Bonus thought: should it distribute v6 IPs as well? That way less hack during host bootstrapping. And it paves the way to a v6 only future.

I think this is worth exploring as it gets rid of the interface tokenisation hack we do in d-i and i think would also allow us to drop the add_ipv6_mapped define all together. would be interested in @BBlack thoughts?