Skip to main content

GitLab export to Ansible Inventory for NetBox

Compatibility

This plugin in compatible with NetBox 2.8 and later.

Installation

First, add netbox_gitlab to your /opt/netbox/local_requirements.txt file. Create it if it doesn't exist.

If you are using a local version of the plugin, for example for development, add -e /opt/path/to/plugin instead.

Then enable the plugin in /opt/netbox/netbox/netbox/configuration.py, like:

PLUGINS = [
    'netbox_gitlab',
]

The plugin needs to be configured. The following settings are required:

PLUGINS_CONFIG = {
    'netbox_gitlab': {
        'url': 'https://gitlab.example.com',
        'private_token': 'aBcDeFgHiJkLmNoPqRsTuVwXyZ',
        'project_path': 'group/project',
    },
}

This example would correspond to the project at https://gitlab.example.com/group/project.

And finally run /opt/netbox/upgrade.sh. This will download and install the plugin and update the database when necessary. Don't forget to run sudo systemctl restart netbox netbox-rq like upgrade.sh tells you!

Usage

This plugin uses NetBox export templates to generate the files that are put into the git repository. The output of these templates is parsed as YAML, but JSON output is also accepted (as all valid JSON is also valid YAML). Generating JSON can be more convenient because of the more relaxed parsing of indentation.

By default this plugin looks for these export templates:

Content type Name Purpose
dcim > device Ansible Inventory A single file listing all devices
dcim > device Ansible Device One file per device with device-level configuration
dcim > interface Ansible Interfaces One file per device with its interface configurations

The output sent to GitLab for the inventory is exactly what the export template produces. The output sent to GitLab for device and interface configurations is always YAML with all the empty variables omitted. This makes it easier when writing export templates while still keeping the output compact. This in turn helps to keep Ansible a bit faster by reducing the time spent on parsing the YAML.

For the devices export template this plugin expects the generated YAML/JSON to be a mapping with the device name as the key. When a device is part of a virtual chassis all members of the virtual chassis will be included.

For the interfaces export template this plugin expects the generated YAML/JSON to be a mapping with the interface name as the key.

Examples of export templates are provided in the git repository of this plugin.

Metadata

Release files for netbox-gitlab 0.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for netbox-gitlab 0.6.1
File Size Uploaded
netbox_gitlab-0.6.1.tar.gz 22.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for netbox-gitlab 0.6.1
File Interpreter ABI Platform
netbox_gitlab-0.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 51.2 kB

Release files / netbox_gitlab-0.6.1.tar.gz

Download URL netbox_gitlab-0.6.1.tar.gz
Size 22.1 kB
Tags Source
SHA-256 checksum
How to use checksums
099202dd6d7117c5e613d46194de16ce0ae779453293e95ac78520d7751acd05
BLAKE2b-256 checksum
How to use checksums
cee841ff3c13b697fb2e52f46686fac8d17577d5f5054c0fb72528b9ecd820ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

Release files / netbox_gitlab-0.6.1-py3-none-any.whl

Download URL netbox_gitlab-0.6.1-py3-none-any.whl
Size 29.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41d172d26bc49e13063240c779c7aaee7ce44b54a26119a04b4fd4431fa64b55
BLAKE2b-256 checksum
How to use checksums
6f1778d947c31a780e3e9d2047cd087bb5d030e2092dcb7b52afce78e99a1fb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 release files

0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page