NetBox

To create and manage device inventory via plugin, several steps are required. This guide covers the NetBox plugin.

Related reading: NetBox inventory source

1

Install the plugin

There is an ansible-galaxy command that can install the plugin into the IAG server. You will likely have to incorporate this command into your IAG build plan so that you do not have to do this as a manual step. For NetBox the command looks like this:

ansible-galaxy collection install netbox.netbox

2

Configure Ansible to use the plugin

There are several ways to accomplish this step. Below is a suggested method for enabling a plugin. Make sure the interpreter_python is appropriate for the environment.

/etc/ansible/ansible.cfg

This example enables the NetBox dynamic inventory plugin.

1[defaults]
2collections_path=/opt/automation-gateway/ansible/collections:/usr/share/ansible/collections
3host_key_checking = False
4timeout = 900
5# This might need adjusting depending on specifics
6interpreter_python = /bin/python3.9
7INVENTORY_ENABLED = "netbox.netbox.nb_inventory"
8
9[persistent_connection]
10command_timeout = 3600
11connect_timeout = 900
3

Configure the host file

Use the NetBox documentation to determine the most appropriate way to configure the plugin to connect to and query from the source of truth system. The NetBox plugin configuration below connects to the public NetBox demo and returns all devices found there.

Be sure to specify the host file as a .yml file.

/opt/automation-gateway/ansible/inventory/hosts.yml

1---
2plugin: netbox.netbox.nb_inventory
3# This is the public netbox demo website. You will need to create a temporary
4# account to create an API token. Admin > Authentication > API Tokens
5api_endpoint: "https://demo.netbox.dev"
6token: aaaaaaaaaaaaaaaaaaaaaaaaaa
7validate_certs: False
8config_context: False
9group_by:
10 - device_roles
4

Confirm the plugin is working

Before invoking the plugin from IAG, test it directly from the command line using Ansible. This command invokes the plugin and returns the devices it finds.

ansible-inventory -vvv --list -i <path-to-plugin-host-file>

5

Restart IAG

Restarting IAG triggers the plugin to execute. Once execution finishes, you should see NetBox devices in the Ansible inventory.