/netbox-labs:netbox-automation-patternsfrom netbox-labs
End-to-end automation patterns with NetBox: event-driven workflows (event rules, webhooks), infrastructure-as-code (Ansible, Terraform), and GitOps integration. Use when building or troubleshooting NetBox automation pipelines.
Ships in netbox-labs. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Your knowledge of NetBox automation tools may be outdated. Ansible collection modules, Terraform provider resources, and event rule behavior change between releases. Prefer retrieval over pre-trained knowledge.
| Source | URL / Method | Use for |
|---|---|---|
| NetBox Ansible collection | https://github.com/netbox-community/ansible_modules | Module list, parameters, examples |
| Ansible docs | https://netboxlabs.com/docs/integrations/tool-integrations/netbox-ansible-collection/ | Integration guide |
| Terraform provider | https://github.com/e-breuninger/terraform-provider-netbox | Resources, data sources |
| Event rules docs | https://netboxlabs.com/docs/netbox/features/event-rules/ | Webhook/script triggers |
| NetBox MCP server | If configured — verify event rules, webhooks exist | Validate automation config |
This skill covers how to integrate NetBox into automation workflows. It spans event-driven triggers, configuration management, infrastructure-as-code, and CI/CD pipelines. This is a cross-cutting skill — it ties together multiple open-source tools around NetBox as the source of truth.
Load this skill when:
Out of scope: NetBox core administration, plugin development, REST/GraphQL API basics (see netbox-api-integration).
| Goal | Tool | Pattern |
|---|---|---|
| React to changes in NetBox | Event Rules + Webhooks | Push notification to external system |
| React to changes internally | Event Rules + Custom Scripts | Run logic inside NetBox |
| Define intended state in NetBox | Ansible modules (netbox.netbox) | Declarative, idempotent |
| Use NetBox as Ansible inventory | nb_inventory plugin | Dynamic inventory from NetBox data |
| Manage NetBox + cloud together | Terraform (e-breuninger/netbox) | IaC lifecycle, state tracking |
| Allocate next available IP/prefix | Terraform available_* resources | Auto-allocation from parent |
| NetBox → config generation → deploy | GitOps pipeline | CI/CD with NetBox as source of truth |
NetBox's event rule system (introduced in 3.7) is the foundation for reactive automation. An event rule matches object changes to actions.
status.value == "active". On 4.7+ conditions can also test the change itself: {"attr": "status", "op": "changed"} plus snapshots.prechange.<attr> / snapshots.postchange.<attr> paths, and a regex operatorwebhook (external HTTP call), script (run a custom script), notification (notify users), plus plugin-registered action types on 4.7+Always scope with conditions — Unscoped event rules fire on every matching change, creating noise and load. Use conditions to target specific statuses, roles, or tags. To fire only on a transition (status becomes active), use the 4.7 changed operator; on 4.5/4.6 compare snapshots.prechange/postchange in the body template instead. On 4.7+ a condition that references a non-existent attribute fails closed and logs — a rule that "stopped firing" after an edit is usually a typo.
Events are async — Don't assume immediate execution. The event is queued to Redis/RQ and processed by a worker. Design receivers to handle delays.
Choose the right action type:
netbox-custom-scripts)Test with the built-in receiver before production:
python netbox/manage.py webhook_receiver # Listens on port 9000
Coalescing behavior — Multiple changes to the same object within one request are coalesced. Only the final state triggers the event. Delete events eagerly serialize data since the object won't exist later.
Bound receiver time (4.7+) — Set a per-webhook timeout (or WEBHOOK_DEFAULT_TIMEOUT, default 60 s); it must stay below RQ_DEFAULT_TIMEOUT. Receivers should acknowledge fast and process asynchronously.
See references/event-rules-and-webhooks.md for payload format, HMAC signing, Jinja2 templating, and security considerations.
The netbox.netbox Ansible collection (GPLv3) provides modules, dynamic inventory, and lookup plugins.
State management — Use modules (netbox_device, netbox_ip_address, etc.) to ensure NetBox objects match desired state. All modules are idempotent with state: present/absent.
Dynamic inventory — Use nb_inventory to generate Ansible inventory from NetBox. Group by device roles, sites, regions, tenants, tags, or platforms.
Data lookup — Use nb_lookup to query NetBox data within playbooks.
Set config_context: False in inventory unless you need it. On 4.5/4.6 this avoids an expensive per-device render server-side; on 4.7+ context is pre-rendered and cached, and the plugin sends ?exclude=config_context (ignored on every 4.7.x — 4.7.3's ?omit= optimisation doesn't reach it, as of netbox.netbox 3.23.1), so the option only trims hostvars.
Use query_filters to limit inventory scope server-side rather than filtering client-side.
Scope tokens properly — Read-only tokens for inventory/lookup, write tokens only for modules that create/modify objects.
Version compatibility — The collection's policy is the two most recent NetBox releases; the latest release (v3.23.1, 2026-10) is CI-tested through 4.5 and declares no 4.6/4.7 support yet. Pin the collection and test against your NetBox minor.
Filter with device_query_filters — e.g., has_primary_ip: 'true' to exclude devices without management IPs.
See references/ansible-patterns.md for module examples, inventory configuration, and lookup patterns.
The e-breuninger/netbox Terraform provider manages NetBox resources as infrastructure-as-code.
Pin provider version to match NetBox version — NetBox makes breaking API changes in minor releases. Check the provider's compatibility matrix: v5.6.1+ covers NetBox 4.3–4.6.5; the v6.0 rewrite (RC as of 2026-09) targets 4.6.8–4.6.10; no release declares 4.7 support yet.
Understand available_* resource lifecycle — netbox_available_ip_address and netbox_available_prefix allocate on create and cannot be "updated." They have unique lifecycle behavior compared to regular resources.
Plan for state drift — If someone modifies NetBox outside Terraform, the next terraform plan shows drift. Decide on a drift remediation strategy.
Coverage varies by area — The provider has strongest coverage for IPAM and virtualization. Other models may have incomplete resource support.
Use data sources for read-only lookups — Most resources have corresponding data sources for referencing existing NetBox objects without managing them.
See references/terraform-patterns.md for provider setup, resource examples, and the available_* allocation pattern.
NetBox integrates into GitOps pipelines as either the source of truth or a state mirror.
| Pattern | Flow | Best For |
|---|---|---|
| Webhook-driven | NetBox change → webhook → CI/CD → deploy | Real-time reactions |
| Polling/export | Cron → export NetBox data → Git commit → CI/CD | Batch config generation |
| Ansible pull | Ansible + nb_inventory → generate configs → push | Playbook-driven workflows |
| Terraform unified | Terraform manages NetBox + infrastructure together | Cloud + NetBox in sync |
Decide on a single source of truth — Either NetBox prescribes state and Git/automation enforces it, or Git is the source and NetBox mirrors it. Don't have two masters.
Use config contexts for template data — Config contexts provide per-device, per-role, or per-site configuration data that Jinja2 templates consume during config generation.
Webhook → CI/CD for real-time pipelines — Combine event rules with webhooks to trigger GitHub Actions, GitLab CI, or Jenkins on NetBox changes.
Use tags as automation hints — Tag interfaces, devices, or prefixes to signal automation intent (e.g., tag "OSPF" on an interface to include it in OSPF config generation).
See references/gitops-workflows.md for pipeline architecture details and examples.
These apply across all automation approaches:
Token management: Use scoped tokens with minimal permissions. Prefer v2 tokens (NetBox 4.5+) with Bearer auth. See netbox-api-integration for token format details.
Rate limiting: Large automation runs (bulk Ansible plays, Terraform applies) should implement backoff to avoid overwhelming the NetBox API. On 4.7+, large custom bulk writes can use ?background=true (HTTP 202 + job URL; poll the job for the result) to avoid proxy timeouts — see netbox-api-integration.
Pagination: All tools (pynetbox, Terraform provider, Ansible collection) handle pagination internally, but be aware of it when writing custom integrations. NetBox 4.6 adds cursor-based start pagination (an efficient alternative to deep offset scans) — see netbox-api-integration.
Idempotency: Ansible modules are idempotent by design. Terraform is declarative. Webhooks are fire-and-forget — implement idempotency on the receiver side.
Testing: Use NetBox's official Docker image for CI/CD testing environments (netboxcommunity/netbox:v4.7-5.1.1; tag = v<netbox>-<netbox-docker>). Spin up a disposable instance for integration tests.
changed/unchanged operators, snapshots.prechange.<attr> / snapshots.postchange.<attr> paths, regex operator; unresolvable attributes fail closed and log to netbox.event_rules. Snapshot values are raw (status, not status.value).username and request_id removed — use request.user / request.id. send_webhook() lost its username argument: drain RQ queues before upgrading or queued webhook jobs fail with TypeError.timeout field and WEBHOOK_DEFAULT_TIMEOUT (default 60); must be less than RQ_DEFAULT_TIMEOUT, else NetBox refuses to start / save.action_object_type optional; plugins register action types (EventRuleAction); action_is_available flags rules whose plugin is gone.{value,label} objects in REST (and thus webhook data); config_context in device/VM output by default (omit it with ?omit=config_context on 4.7.3+; ?exclude= is a no-op on 4.7); ipam.Service protocol/ports deprecated for port_mappings; bulk write errors are per-object; ?background=true on bulk writes.v4.7-5.1.1) requires NetBox 4.7+; Ansible collection and Terraform provider have not declared 4.7 support (see references).request object; username/request_id deprecated.start pagination for large reads.username/request_id exist in the webhook context.| Document | When to Load |
|---|---|
| references/event-rules-and-webhooks.md | Building webhook integrations, configuring event rules, debugging webhook delivery |
| references/ansible-patterns.md | Writing Ansible playbooks that manage or query NetBox |
| references/terraform-patterns.md | Managing NetBox resources with Terraform |
| references/gitops-workflows.md | Designing CI/CD pipelines with NetBox in the loop |
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub netboxlabs/skills --plugin netbox-labs22 skills in this plugin
/netboxHub skill for the NetBox ecosystem. Routes to specialized skills for data modeling, API integration, plugin development, change management, discovery, assurance, automation, and migration. Load this skill first to find the right specialist.
/netbox-administrationNetBox server administration: configuration, authentication backends (local/LDAP/SAML/OIDC), object permissions, API tokens, performance tuning, backups, upgrades, and housekeeping. Use when managing a NetBox instance rather than consuming its API.
/netbox-api-integrationBest practices for building integrations with NetBox REST and GraphQL APIs. Use when building NetBox API integrations, reviewing integration code, troubleshooting NetBox performance issues, planning automation architecture, writing scripts that interact with NetBox, using pynetbox, configuring Diode for data ingestion, or implementing NetBox webhooks and branching workflows.
/netbox-asset-lifecycleNetBox Asset Lifecycle — a commercial NetBox Labs feature that tracks equipment procurement from plan to install (BOMs, vendors, purchase orders, shipments, receiving) plus spares pools with stock-level allocations. Use when working with the asset-lifecycle REST or GraphQL API, driving greenfield procurement or brownfield sparing workflows over the API (generate BOM, install from shipment or spare, archive), or modeling vendors, purchase orders, shipments, and spares.
/netbox-assuranceNetBox Assurance drift detection and deviation management. Use when working with network state comparison, deviation review/remediation, data source configuration, or understanding how intended vs actual network state is reconciled in NetBox Cloud and Enterprise.
/netbox-branchingNetBox Branching plugin — create isolated branch schemas for safe change staging, review, and merge. Use when working with branch lifecycle, the X-NetBox-Branch header, async provisioning/sync/merge jobs, conflict resolution, or Change Request integration.
Other plugins' skills for the same job