Before we start generating configurations with Ansible, we need to connect Ansible to Netbox.
In order to pull data from Netbox, we need to generate a token. This can be done in the administrative screen.
For more information on authentication methods visit the Authentication documentation
Otherwise, generate your token and copy it.
Now we need to create a yaml configuration file to use as the dynamic inventory for Ansible.
For more information on the netbox plugin, visit the Netbox Plugin documentation
My configuration file is below
---
plugin: netbox
api_endpoint: https://netbox-server-here
token: token-here
validate_certs: False
config_context: True
group_by:
- device_roles
compose:
ansible_network_os: platform.slug
Save this file as netbox_inventory.yml
You can test your integration by running
ansible-inventory -v --list -i netbox_inventory.yml