feat: NetBox IP/interface facts with offline cache #506
Reference in New Issue
Block a user
Delete Branch "benvin/netbox-facts"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
Nodes need their authoritative IP/interface data from NetBox, but a NetBox outage must never become a fleet-wide puppet failure. Static IPs never change (a replacement is a new machine), so stale cache is always safe.
Changes
netboxfact (modules/libs/lib/facter/netbox.rb): queries NetBox (dcim devices + virtualization VMs) by fqdn/hostname; emitssource,name,primary_ip,interfaces[](name, mac, ips, primary),fetched_at,cached./var/cache/puppet-netbox/facts.json(0600). On any failure (short 3s/5s timeouts, DNS, non-200, parse) it serves the cached payload withcached: true. Never-cached host returns nothing; the fact never raises. No TTL expiry - correctness beats freshness.profiles::netbox::facts: inert until$api_tokenset; writes root-only/etc/puppetlabs/netbox.token(0600),/etc/puppetlabs/netbox.url, and the cache dir. Confined off (no-op) where the token is absent. Included fromprofiles::base.Seeding the token (follow-up)
Set the eyaml secret
profiles::netbox::facts::api_token(a read-only NetBox API token) in hieradata -common.eyamlfor fleet-wide, or scoped to the roles that need it. Until then the fact is a no-op everywhere.Manual test (one host)
Transform + cache-fallback + never-cached + 0600 verified locally with a stubbed NetBox (17 assertions).
https://claude.ai/code/session_01JUoARVdmhxKQHyyyp1pxeT
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.