Skip to content

Add NetBox to Infrahub sync tutorial#134

Closed
estivate wants to merge 9 commits into
mainfrom
feature/netbox-demo-tutorial-docs
Closed

Add NetBox to Infrahub sync tutorial#134
estivate wants to merge 9 commits into
mainfrom
feature/netbox-demo-tutorial-docs

Conversation

@estivate

@estivate estivate commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds an end-to-end tutorial (docs/docs/tutorials/netbox-demo-to-infrahub.mdx) that walks a reader from zero — no existing Infrahub instance required — through scaffolding a project, starting Infrahub, installing Infrahub Sync, loading a schema, and running a first NetBox → Infrahub sync against the public NetBox demo. Readers who already have Infrahub running are pointed straight to the NetBox adapter docs instead.
  • Reworks the example sync config (examples/netbox_to_infrahub/config.yml) to target the production-grade schema-library schema instead of the ad-hoc example schema used previously, covering DCIM, IPAM, and organization objects with the same core domains as NetBox.
  • Adds a "Tutorials" section to docs/sidebars.ts.

What's covered

Sites, racks, devices and interfaces, VRFs/VLANs, prefixes/IP addresses, circuits, tags, and organizations (manufacturers, providers, RIRs).

Known limitations / follow-ups

  • Mapping coverage: several NetBox object types aren't mapped yet (clusters, compute/VMs, cables, provider networks, tenants, device-type templates, roles, Q-in-Q) — tracked with inline TODOs in config.yml.
  • Sync customization: there's still a fair amount of work ahead on giving people the tools (e.g. skills) to build and adapt their own sync logic instead of just copying this example config.
  • Tutorial flow: some commands will likely change soon — the manual schema-library curl loop and the pinned-commit config download are stand-ins until schema distribution moves through the marketplace and config distribution firms up.

Adds a tutorial for syncing public NetBox demo data into a local Infrahub instance and exposes it in the docs sidebar.

Validation:

- uv run pytest -q

- npx markdownlint-cli2 "docs/docs/**/*.{md,mdx}"

- uv run invoke docs.docusaurus

Generated with Codex.
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a new tutorial page for syncing the public NetBox demo into Infrahub, updates the docs sidebar to surface it, and rewrites the example sync configuration to use environment-based credentials with expanded DCIM, interface, circuit, and IPAM mappings.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a NetBox-to-Infrahub sync tutorial.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 18, 2026

Copy link
Copy Markdown

Deploying infrahub-sync with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1213a7d
Status: ✅  Deploy successful!
Preview URL: https://ea4c95b2.infrahub-sync.pages.dev
Branch Preview URL: https://feature-netbox-demo-tutorial.infrahub-sync.pages.dev

View logs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/docs/tutorials/netbox-demo-to-infrahub.mdx`:
- Around line 435-439: The bash command in the token troubleshooting section
checks the wrong environment variable. Instead of echoing INFRAHUB_ADDRESS,
update the command to verify that INFRAHUB_API_TOKEN is actually set and
exported. Replace the echo command that references INFRAHUB_ADDRESS with a
command that checks for the presence of INFRAHUB_API_TOKEN and provides clear
feedback on whether the token environment variable is properly configured for
authentication.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8a8a9674-104d-4ac3-a7b7-625ca4465ccd

📥 Commits

Reviewing files that changed from the base of the PR and between dbb8b52 and 0785d60.

📒 Files selected for processing (2)
  • docs/docs/tutorials/netbox-demo-to-infrahub.mdx
  • docs/sidebars.ts

Comment thread docs/docs/tutorials/netbox-demo-to-infrahub.mdx Outdated
estivate added 2 commits June 22, 2026 08:27
Refreshes the tutorial after local validation: pins commands to the published 2.0.0 package, documents demo token and startup behavior, aligns verification with current public NetBox data, and keeps the order guidance focused on auto-derived write ordering.

Also fixes the NetBox example config serial_number Transformation expression by removing a stray trailing brace and corrects the dmi01 comment so reviewers can inspect that config change directly.

Generated with Codex.
@estivate

Copy link
Copy Markdown
Contributor Author

Updated this PR after local tutorial validation. Main changes:

  • Merged latest main into the branch.
  • Refined the NetBox demo tutorial around the published infrahub-sync==2.0.0 package, NetBox token copying, Infrahub startup readiness, auto-derived write order, and verification commands that match current demo data.
  • Added a short note that the example config filters devices/interfaces to dmi01, so the public demo may show no devices.

Reviewer attention requested: this also includes a small non-doc fix in examples/netbox_to_infrahub/config.yml. The InfraDevice serial_number Transformation had an extra trailing } in {{ serial.lower() if serial else '' }}}, which Jinja renders as a literal brace if the Transformation runs. I changed it to {{ serial.lower() if serial else '' }} and corrected the nearby dmu01 comment typo to dmi01.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/docs/tutorials/netbox-demo-to-infrahub.mdx (1)

1-545: ⚠️ Potential issue | 🟠 Major

Fix markdownlint-cli2 line-length violations.

The file fails markdownlint-cli2 validation with 4 line-length errors (MD013). All lines must be 80 characters or fewer:

  • Line 5: 110 characters (30 over limit)
  • Line 6: 103 characters (23 over limit)
  • Line 31: 89 characters (9 over limit)
  • Line 191: 114 characters (34 over limit)

Shorten these lines to pass the markdownlint-cli2 check required by the coding guidelines for documentation files.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/docs/tutorials/netbox-demo-to-infrahub.mdx` around lines 1 - 545, The
markdown file has four lines that exceed the 80-character line-length limit
required by markdownlint-cli2: Line 5 (110 characters) which contains the
opening sentence about using Infrahub Sync to copy data from NetBox demo, Line 6
(103 characters) which continues about starting from scratch, Line 31 (89
characters) which mentions linking to related pages, and Line 191 (114
characters) which is in the normalization section. Break each of these lines
into multiple shorter lines that each stay under 80 characters while preserving
the meaning and markdown formatting, ensuring no content is lost or modified
beyond line wrapping.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@docs/docs/tutorials/netbox-demo-to-infrahub.mdx`:
- Around line 1-545: The markdown file has four lines that exceed the
80-character line-length limit required by markdownlint-cli2: Line 5 (110
characters) which contains the opening sentence about using Infrahub Sync to
copy data from NetBox demo, Line 6 (103 characters) which continues about
starting from scratch, Line 31 (89 characters) which mentions linking to related
pages, and Line 191 (114 characters) which is in the normalization section.
Break each of these lines into multiple shorter lines that each stay under 80
characters while preserving the meaning and markdown formatting, ensuring no
content is lost or modified beyond line wrapping.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5e0c4f13-487b-45e4-ae44-0095e247f39d

📥 Commits

Reviewing files that changed from the base of the PR and between 0785d60 and f22e9d3.

📒 Files selected for processing (3)
  • docs/docs/tutorials/netbox-demo-to-infrahub.mdx
  • docs/sidebars.ts
  • examples/netbox_to_infrahub/config.yml
✅ Files skipped from review due to trivial changes (1)
  • docs/sidebars.ts

Comment on lines +63 to +66
python3 -m venv .venv
source .venv/bin/activate
pip install "infrahub-sync==2.0.0" pynetbox
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We very strongly recommend using UV (or poetry) to manage dependencies

Comment on lines +88 to +92
cd ~/repos
git clone https://github.com/opsmill/infrahub.git
cd infrahub
export INFRAHUB_INITIAL_ADMIN_TOKEN="06438eb2-8019-4776-878c-0941b1f1d1ec"
docker compose up -d

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to clone the entire repository, it's possible to just curl the docker compose file https://docs.infrahub.app/deploy-manage/install-configure/install/community

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I don't think export INFRAHUB_INITIAL_ADMIN_TOKEN="06438eb2-8019-4776-878c-0941b1f1d1ec" is needed as it's already the default value


```bash
cd ~/repos/demo-infrahub-sync
infrahubctl schema load ~/repos/infrahub/models/examples/netbox/netbox.yml

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually this will change and point to the new schema

minitriga
minitriga previously approved these changes Jul 7, 2026
@minitriga minitriga dismissed their stale review July 7, 2026 11:38

Accident

@BaptisteGi BaptisteGi requested a review from a team as a code owner July 7, 2026 12:06

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/netbox_to_infrahub/config.yml`:
- Around line 211-293: The config defines two DcimDevice mappings with the same
kind, but incremental sync uses the first match from list_changed_since(), so
site-only devices are skipped. Update the DcimDevice entries in the
Netbox-to-Infrahub config to use a single mapping with combined rack/site filter
logic, or adjust the lookup in list_changed_since() to consider all matching
schema_mapping entries instead of stopping at the first one.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a6507911-171b-42a0-9bcd-1f68ff841385

📥 Commits

Reviewing files that changed from the base of the PR and between f22e9d3 and 441c33a.

📒 Files selected for processing (1)
  • examples/netbox_to_infrahub/config.yml

Comment on lines +211 to +293
- name: DcimDevice
identifiers: ["location", "name"]
mapping: dcim.devices
fields:
- name: name # /!\ Netbox allows duplicate device names within a virtual-chassis.
mapping: name
- name: serial
mapping: serial
- name: description
mapping: description
- name: position
mapping: position
- name: rack_face
mapping: face.value
- name: status
mapping: status.value
# NOTE: schema changes are required to support role sync (see related note)
# - name: role
# mapping: role.slug
- name: device_type
mapping: device_type
reference: DcimDeviceType
- name: platform
mapping: platform
reference: DcimPlatform
- name: location
mapping: rack
reference: LocationRack
- name: tags
mapping: tags
reference: BuiltinTag
- name: primary_address
mapping: primary_ip
reference: IpamIPAddress
filters:
- field: parent_device # Most lickely for sub-devices (e.g. stacks...) you'd have a dedicated node in Infrahub
operation: "is_empty"
- field: rack
operation: "is_not_empty"
- field: name # /!\ Netbox allows empty name for devices
operation: "is_not_empty"

- name: DcimDevice
identifiers: ["location", "name"]
mapping: dcim.devices
fields:
- name: name
mapping: name
- name: serial_number
- name: serial
mapping: serial
- name: asset_tag
mapping: asset_tag
- name: description
mapping: description
- name: model
- name: position
mapping: position
- name: rack_face
mapping: face.value
- name: status
mapping: status.value
# NOTE: schema changes are required to support role sync (see related note)
# - name: role
# mapping: role.slug
- name: device_type
mapping: device_type
reference: ChoiceDeviceType
- name: organization
mapping: tenant
reference: OrganizationGeneric
- name: role
mapping: role
reference: RoleGeneric
# - name: status
# mapping: status
# reference: StatusGeneric
reference: DcimDeviceType
- name: platform
mapping: platform
reference: DcimPlatform
- name: location
mapping: site
reference: LocationGeneric
- name: rack
mapping: rack
reference: InfraRack
reference: LocationSite
- name: tags
mapping: tags
reference: BuiltinTag
# Showcase Filters
# It will import the ones with dmu01 in their name *AND* without pdu
- name: primary_address
mapping: primary_ip
reference: IpamIPAddress
filters:
- field: name
operation: "contains"
value: "dmi01"
- field: name
operation: "not contains"
value: "pdu"
# Showcase Transforms
transforms:
- field: name
expression: "{{ name.lower() if name else '' }}"
- field: serial_number
expression: "{{ serial.lower() if serial else '' }}}"
- field: parent_device
operation: "is_empty"
- field: rack
operation: "is_empty"
- field: name # /!\ Netbox allows empty name for devices
operation: "is_not_empty"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect how schema_mapping entries are enumerated vs. looked up by name.
fd -e py . infrahub_sync | xargs rg -nP -C3 '\bschema_mapping\b'
# Specifically any name-based single lookups that could miss duplicate names.
rg -nP -C3 'next\(\s*\(?e for e in .*schema_mapping' infrahub_sync
# Any de-dup or grouping by element name during full model_loader.
rg -nP -C3 'model_loader|for .* in .*schema_mapping' infrahub_sync

Repository: opsmill/infrahub-sync

Length of output: 50377


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== netbox adapter =="
sed -n '1,220p' infrahub_sync/adapters/netbox.py

echo
echo "== sync loop / cursor handling =="
sed -n '150,240p' infrahub_sync/__init__.py

echo
echo "== config schema model and order fields =="
sed -n '70,140p' infrahub_sync/__init__.py

echo
echo "== duplicate-name behavior in example config =="
python3 - <<'PY'
from pathlib import Path
p = Path("examples/netbox_to_infrahub/config.yml")
text = p.read_text()
for needle in ["- name: DcimDevice", "mapping: dcim.devices", "operation: \"is_empty\"", "operation: \"is_not_empty\""]:
    print(f"{needle}: {text.count(needle)}")
PY

Repository: opsmill/infrahub-sync

Length of output: 16591


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== where incremental extraction calls list_changed_since =="
rg -n -C 3 'list_changed_since\(' infrahub_sync

echo
echo "== where cursor tiers drive incremental vs full loads =="
rg -n -C 3 'cursor_tier_for\(|CursorTier|incremental' infrahub_sync

echo
echo "== netbox adapter name lookup sites =="
rg -n -C 3 'next\(\s*\(e for e in self\.config\.schema_mapping if e\.name == model_name\)' infrahub_sync/adapters/netbox.py

echo
echo "== example config incremental block =="
rg -n -C 3 '^incremental:|full_resync_every|order:|schema_mapping:' examples/netbox_to_infrahub/config.yml

Repository: opsmill/infrahub-sync

Length of output: 23779


Duplicate DcimDevice mappings skip site-only devices on incremental runs. list_changed_since() takes the first schema_mapping entry for a kind, so cursor-driven syncs will only apply the rack-filtered block here. Merge the rack/site filters into one mapping, or make the incremental lookup handle all matching entries.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/netbox_to_infrahub/config.yml` around lines 211 - 293, The config
defines two DcimDevice mappings with the same kind, but incremental sync uses
the first match from list_changed_since(), so site-only devices are skipped.
Update the DcimDevice entries in the Netbox-to-Infrahub config to use a single
mapping with combined rack/site filter logic, or adjust the lookup in
list_changed_since() to consider all matching schema_mapping entries instead of
stopping at the first one.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/docs/tutorials/netbox-demo-to-infrahub-v2.mdx`:
- Around line 146-153: The tutorial examples in the Infrahub Sync setup still
expose the seeded API token in both the environment export block and the later
snippet, so replace those hardcoded credential values with a redacted
placeholder or a token-acquisition step. Update the examples around the
INFRAHUB_ADDRESS and INFRAHUB_API_TOKEN usage to keep them minimal and
copy/paste-safe, and ensure the surrounding text no longer implies the published
token should be reused.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b74145e4-b1b0-415d-9cce-cc45dad1e829

📥 Commits

Reviewing files that changed from the base of the PR and between 441c33a and 03c85b4.

📒 Files selected for processing (2)
  • docs/docs/tutorials/netbox-demo-to-infrahub-v2.mdx
  • examples/netbox_to_infrahub/config.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • examples/netbox_to_infrahub/config.yml

Comment thread docs/docs/tutorials/netbox-demo-to-infrahub-v2.mdx Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants