Netbox Ansible role https://netboxlabs.com/
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-03 09:41:31 +00:00
.forgejo/workflows breaking: added initial version 2026-11-03 10:09:26 +01:00
defaults feat: added netbox mcp 2026-11-03 10:40:23 +01:00
meta breaking: added initial version 2026-11-03 10:09:26 +01:00
tasks feat: added netbox mcp 2026-11-03 10:40:23 +01:00
templates feat: added netbox mcp 2026-11-03 10:40:23 +01:00
vars breaking: added initial version 2026-11-03 10:09:26 +01:00
.gitignore breaking: added initial version 2026-11-03 10:09:26 +01:00
CHANGELOG.md feat: added netbox mcp 2026-11-03 10:40:23 +01:00
LICENSE breaking: added initial version 2026-11-03 10:09:26 +01:00
README.md Prettified Code! 2026-11-03 09:41:31 +00:00

netbox

Ansible role that runs NetBox as a Docker Compose service behind Traefik, using the official netbox-docker image (docker.io/netboxcommunity/netbox). The compose file is the role's own (no git clone of netbox-docker); it follows upstream's docker-compose.yml:

  • netbox (Granian, port 8080) and netbox-worker (RQ worker)
  • postgres (PostgreSQL 18)
  • redis (Valkey, persistent task queue) and redis-cache (Valkey, volatile)

Optionally users log in through an OIDC provider (e.g. Keycloak). The local superuser stays available as break-glass login.

Data and secrets

  • netbox_data_path (/data/netbox): postgres/, redis/, media/, reports/, scripts/ and dump/netbox.dump, a nightly pg_dump -Fc (netbox_db_dump_cron). Back up this directory; restore the database with pg_restore -c -U netbox -d netbox.
  • netbox_docker_path (/docker/netbox): compose file, zz_ansible.py (extra settings, mounted to /etc/netbox/config/), oidc_group_sync.py and secrets/.
  • Secret key, API token pepper and database password are generated once on the host (secrets/netbox/) and kept. The superuser password and the OIDC client secret come from the inventory. netbox-docker reads all of them from /run/secrets/<name>.
  • Valkey runs without a password: it is only on the internal Compose network.

The superuser is created on start if it doesn't exist; changing netbox_superuser_password later has no effect (change it in NetBox). No API token is created; create tokens in the UI.

No data leaves the host

Always set (override only via netbox_env):

  • ISOLATED_DEPLOYMENT=true: no census report, no release check, no plugin catalog fetch, Copilot can't load.
  • COPILOT_ENABLED=false: NetBox Copilot (a script from static.copilot.netboxlabs.ai that sends what users ask and see to NetBox Labs) is off. Set in the configuration, it can't be switched on in the UI.
  • CENSUS_REPORTING_ENABLED=false, RELEASE_CHECK_URL unset.

What still talks out: the OIDC calls to the IdP, and whatever admins configure themselves (webhooks, remote data sources, MAPS_URL links clicked in the browser).

MCP server

netbox_mcp_enabled adds netbox-mcp-server (docker.io/netboxlabs/netbox-mcp-server), read-only by design (get_objects, get_object_by_id, get_changelogs), HTTP transport on port 8000, path /mcp.

  • It calls NetBox at http://netbox:8080/ over the Compose network mcp, which is internal (no internet access). FastMCP telemetry (FASTMCP_TELEMETRY_MODE=off) and update checks (FASTMCP_CHECK_FOR_UPDATES=off) are off.
  • netbox_mcp_netbox_token: a NetBox API token of a dedicated user with read-only permissions (create user, permission with action "view" only, and token in NetBox first). What the token can read is what every MCP client can read.
  • netbox_mcp_auth_token: Bearer token clients must send. Required; the endpoint is otherwise unauthenticated.
  • netbox_mcp_domain: optional Traefik route (https://<domain>/mcp). Without it the server is only reachable from containers of this compose project. With it, the container also joins traefik_web, which has internet access - keep the IP allowlist at haproxy (internal sources only).

OIDC single sign-on

Setting netbox_oidc_endpoint (issuer URL, without /.well-known/openid-configuration) enables it. Redirect URI at the provider: https://<netbox_domain>/oauth/complete/oidc/.

NetBox has no group sync for SSO logins (REMOTE_AUTH_GROUP_SYNC_ENABLED and REMOTE_AUTH_SUPERUSER_GROUPS only apply to the HTTP header backend), so the role ships a python-social-auth pipeline step (templates/oidc_group_sync.py.j2):

  • netbox_oidc_group_sync_map: provider group -> NetBox group(s). The NetBox groups must exist. With netbox_oidc_group_sync_strict (default) users are removed again from mapped groups whose provider group is gone. Unmapped NetBox groups are never touched.
  • netbox_oidc_superuser_groups / netbox_oidc_staff_groups: provider groups that grant is_superuser / is_staff; the flag is revoked from users in none of them.
  • The groups come from the claim netbox_oidc_group_claim (default groups), in the userinfo response or the ID token. Keycloak needs a group membership mapper on the client (full.path: false).
  • Without any of them, SSO users get no permissions and see nothing (LOGIN_REQUIRED).

netbox_oidc_pipeline freezes NetBox's SOCIAL_AUTH_PIPELINE (checked against v4.7.4). Compare it with netbox/settings.py after an upgrade. The sync logs to netbox.auth.oidc_group_sync.

Updating

Bump netbox_version (<NetBox>-<netbox-docker>, e.g. v4.7.4-5.1.1). Migrations run on start, before the healthcheck passes (up to wait_timeout 900 s). Read the NetBox release notes for upgrade paths; keep the PostgreSQL major (netbox_postgres_version) in step with netbox-docker - a major upgrade needs a dump/restore.

Requirements

  • Docker with the Compose plugin on the host, openssl and cron.
  • Traefik on the host with the external network traefik_web (when netbox_traefik is true).

Variables

Variable Default Description
netbox_instance netbox Compose project name and container prefix.
netbox_docker_path /docker/netbox Compose file, extra config, secrets.
netbox_data_path /data/netbox Database, queue, media, reports, scripts, dump.
netbox_version v4.7.4-5.1.1 netboxcommunity/netbox tag.
netbox_postgres_version 18.6-alpine postgres tag.
netbox_valkey_version 9.1.3-alpine valkey/valkey tag.
netbox_domain ~ Required. Public domain (also ALLOWED_HOSTS, CSRF origin).
netbox_traefik true Traefik labels and the traefik_web network.
netbox_traefik_certresolver default Traefik certificate resolver.
netbox_extra_hosts {} /etc/hosts entries for all containers (no NAT hairpin).
netbox_workers 2 Granian worker processes.
netbox_env {} Extra netbox-docker environment variables, merged over the role's.
netbox_superuser_username admin Local superuser.
netbox_superuser_email ~ Required.
netbox_superuser_password ~ Required. Only used when the user is created.
netbox_ram_base_unit 1024 1024 = MiB/GiB, 1000 = MB/GB.
netbox_disk_base_unit 1024 Same for disks.
netbox_db_dump_cron 30 2 * * * Nightly pg_dump, ~ disables it.
netbox_oidc_endpoint ~ Issuer URL, enables SSO.
netbox_oidc_client_id ~ Required with SSO.
netbox_oidc_client_secret ~ Required with SSO.
netbox_oidc_display_name Single sign-on Login button label.
netbox_oidc_username_claim preferred_username Claim for the username.
netbox_oidc_extra_scopes [] Scopes on top of openid profile email.
netbox_oidc_default_groups [] NetBox groups every SSO user is added to.
netbox_oidc_logout_redirect_url / Redirect after logout.
netbox_oidc_group_sync_map {} Provider group -> NetBox group(s).
netbox_oidc_group_claim groups Claim with the group names.
netbox_oidc_group_sync_strict true Also remove mapped groups.
netbox_oidc_superuser_groups [] Provider groups granting is_superuser.
netbox_oidc_staff_groups [] Provider groups granting is_staff.
netbox_oidc_pipeline NetBox's + sync SOCIAL_AUTH_PIPELINE when the sync is active.
netbox_mcp_enabled false Add the read-only MCP server.
netbox_mcp_version 1.2.1 netboxlabs/netbox-mcp-server tag.
netbox_mcp_netbox_token ~ Read-only NetBox API token. Required with MCP.
netbox_mcp_auth_token ~ Bearer token for MCP clients, 32+ characters. Required with MCP.
netbox_mcp_domain ~ Traefik route for the MCP endpoint, ~ = none.
netbox_uninstall false Remove containers, compose directory and dump job.
netbox_purge false With netbox_uninstall, also remove netbox_data_path.

Example

- hosts: netbox
  roles:
    - netbox
  vars:
    netbox_domain: net.example.org
    netbox_superuser_email: it@example.org
    netbox_superuser_password: "{{ vault_netbox_admin_password }}"
    netbox_oidc_endpoint: https://auth.example.org/realms/example
    netbox_oidc_client_id: netbox
    netbox_oidc_client_secret: "{{ vault_netbox_oidc_secret }}"
    netbox_oidc_superuser_groups: [netbox admins]
    netbox_extra_hosts:
      auth.example.org: 10.0.0.2