Rake task to clean up DHCP records

Hey,

this is something we needed for a very long time, finally I found some time to work on it. It’s a simple script (rake task) which goes over managed hosts in a subnet and compares that to DHCP Smart Proxy information:

  • Records not found on DHCP Smart Proxy are recreated.
  • DHCP entries not found in Foreman database are deleted.

Backup dhcpd.leases file prior running the script! Then copy it [1] over to /usr/share/foreman/lib/tasks and run:

foreman-rake orchestration:dhcp:cleanup subnet_name=subnet_199_202

Some logs will be available in the production.log to see what happened. Hopefully this will get merged into Foreman core so it’s available for everyone.