netbox adapter

Inmanta module to manage netbox inventory

Features

The module supports all existing netbox resources used for networking documentation. Netbox-Secret is also supported.

Supported Netbox versions

The table below lists the Netbox versions supported by this module, together with the matching netbox-secrets plugin version (only required when using the secret features of the module). Netbox 4.1 and older are not supported: the module follows the scoped-object api (scope_type/scope_id on clusters, prefixes, …) introduced in Netbox 4.2.

Netbox version

netbox-secrets version

4.6

3.1.x

4.5

3.0.x

4.4

2.4.x

4.3

2.3.x

4.2

2.2.x

CI testing policy

Which of the supported versions the test suite runs against depends on the type of build:

  • on every commit: only the latest supported version

  • nightly builds: the latest and the oldest supported versions

  • weekly builds: all supported versions

The ci-test make target implements this policy based on the NIGHTLY_BUILD and WEEKLY_BUILD environment variables set by the build pipeline. To run the test environment for a specific version locally, pass the version to the make targets, e.g. make netbox-up NETBOX_VERSION=4.4.

Environment variables

Env variable name

Description

NETBOX_USER

Netbox username, only required if you use netbox-secrets.

NETBOX_PASSWORD

Netbox password, only required if you use netbox-secrets.

NETBOX_API_TOKEN

Netbox api token, used as main credentials to interact with netbox.
Only required if you use netbox::Credentials with api_token_env_var.

INMANTA_NETBOX_SERIALIZE_SECRET_REQUESTS

When set to a non-empty value, all the requests made towards netbox-secrets when resolving secret references are serialized behind a lock.
Use this to reduce the load on the netbox server when a lot of agents are deploying at the same time.

Netbox-Secret

All information relative to Netbox-Secret can be found in the secret.md file

Usage example

This simple example shows how to document a Device (server-1) with its cluster, rack, site and tenant:

import netbox
import netbox::resources
import restbase

credentials = netbox::Credentials(
    url="http://1.2.3.4:8000",
    api_token="abcdefg",
    agent_autostart=false
)

tenant_group=netbox::resources::TenantGroup(
    credentials=credentials,
    name="tenant_group_1",
    slug="tenant_group_1",
    purged=false,
)

tenant=netbox::resources::Tenant(
    credentials=credentials,
    name="tenant1",
    slug="tenant1",
    group=tenant_group,
    purged=false,
)

site = netbox::resources::Site(
    credentials=credentials,
    name="SITE",
    slug="site",
    tenant=tenant,
    purged=false,
)

rack1 = netbox::resources::Rack(
    credentials=credentials,
    name="rack-1",
    site=site,
    tenant=tenant,
    purged=false,
)

lenovo = netbox::resources::Manufacturer(
    credentials=credentials,
    name="Lenovo",
    slug="lenovo",
    purged=false
)

se450 = netbox::resources::DeviceType(
    credentials=credentials,
    model="SE450",
    slug="se450",
    manufacturer=lenovo,
    purged=false,
)

server_role = netbox::resources::DeviceRole(
    credentials=credentials,
    name="server",
    slug="server",
    purged=false,
)

cluster_type = netbox::resources::ClusterType(
    credentials=credentials,
    name="esxi",
    slug="esxi",
    purged=false
)

cluster1 = netbox::resources::Cluster(
    credentials=credentials,
    type=cluster_type,
    name="server-1",
    site=site,
    tenant=tenant,
    purged=false,
)

device_server = netbox::resources::Device(
    credentials=credentials,
    name="server-1",
    site=site,
    rack=rack1,
    tenant=tenant,
    device_type = se450,
    role = server_role,
    cluster=cluster1,
    purged=false
)