Skip to content

Instantly share code, notes, and snippets.

@nomaster
Last active July 8, 2021 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomaster/c5a0b1a904a9c1342fcfd6b2df75017e to your computer and use it in GitHub Desktop.
Save nomaster/c5a0b1a904a9c1342fcfd6b2df75017e to your computer and use it in GitHub Desktop.
NetBox inventory for Ansible
---
plugin: netbox.netbox.nb_inventory
cache: True
cache_connection: .inventory
cache_plugin: jsonfile
plurals: False
group_by:
- platform
- role
- region
# export NETBOX_API=https://your.net.box
# export NETBOX_TOKEN=YourPersonalNetBoxAccessToken
# ansible-inventory -i netbox_inventory.yml --list
@nomaster
Copy link
Author

nomaster commented Jul 8, 2021

This fetches the Ansible inventory from your NetBox. It will group your devices by some parameters, which seem generally useful to me - feel free to change!

@nomaster
Copy link
Author

nomaster commented Jul 8, 2021

Also, it will cache the result of the NetBox API call for an hour in the directory .inventory. To purge the cache, simply remove this dir.

The NetBox API is somewhat slow, see issue netbox-community/netbox#6423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment