Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative netbox.netbox.nb_inventory_inventory #5

Open
ypid opened this issue Nov 1, 2020 · 2 comments
Open

Alternative netbox.netbox.nb_inventory_inventory #5

ypid opened this issue Nov 1, 2020 · 2 comments

Comments

@ypid
Copy link
Contributor

ypid commented Nov 1, 2020

It looks to me that this script got deprecated by https://netbox-ansible-collection.readthedocs.io/en/latest/plugins/inventory/nb_inventory/netbox.netbox.nb_inventory_inventory.html. The reason I looked into netbox-joined-inventory was that it provides a nice way to generate inventory files that one can review. I have now tested a way to get a similar behavior with netbox.netbox.nb_inventory:

ansible/inventory/netbox.yml:

---
# vim: foldmarker=[[[,]]]:foldmethod=marker

plugin: netbox.netbox.nb_inventory
token: invalid
## More netbox.netbox.nb_inventory settings.

## 60 * 60 * 24 * 360 * 1000
cache_timeout: 31104000000

ansible/refresh-netbox.yml:

---
# vim: foldmarker=[[[,]]]:foldmethod=marker

plugin: netbox.netbox.nb_inventory
## More netbox.netbox.nb_inventory settings.

cache_timeout: 10

ansible.cfg:

[inventory]
cache = True
cache_plugin = jsonfile
cache_connection = ~/.ansible/inventory_cache

Makefile:

.PHONY: refresh-netbox
refresh-netbox: ansible/inventory/netbox.yml
	@echo "## This file is managed by a Makefile, all changes will be lost.\n" > ansible/refresh-netbox.yml
	sed 's/^cache_timeout:.*/cache_timeout: 10/;/^token: invalid$$/d;s/^# real token:/token:/;' "$<" >> ansible/refresh-netbox.yml
	ansible-inventory -v --list -i ansible/refresh-netbox.yml | less
	git -C ~/.ansible/inventory_cache diff
	git -C ~/.ansible/inventory_cache add .
	git -C ~/.ansible/inventory_cache commit -m "Auto commit after review"

To refresh the cache, run ansible-inventory -v --list -i ansible/refresh-netbox.yml and then review the changes in ~/.ansible/inventory_cache or make refresh-netbox.

You could also use ansible-playbook --diff --check in combination with manual cache refresh.

What do you think?

@marioland
Copy link
Contributor

If I understood the netbox.netbox.nb_inventory right it is able to generate a dynamic inventory in a generic way. With your addition it would also be able to export the inventory to files.

On the other hand the netbox-joined-inventory is part of a networking stack that is able to configure switches. It can take all VLAN, VXLAN, Anycast, MLAG , BGP data and more all from netbox.
Therefore netbox-joined-inventory needs to join a lot of tables from netbox.
See https://github.com/Sidarion/netbox-joined-inventory data model.
After all the joining netbox-joined-inventory will produce the static files that ansible can take as inventory and all details in the detailed host_vars files.

As all this joining is very specific to this networking stack I doubt that the more generic netbox.netbox.nb_inventory could replace the netbox-joined-inventory.

@ypid ypid changed the title Deprecated by netbox.netbox.nb_inventory_inventory Alternative netbox.netbox.nb_inventory_inventory Nov 2, 2020
@ypid
Copy link
Contributor Author

ypid commented Nov 2, 2020

Right. That is the thing I was not sure about, how difficult it would be to implement your use case with the generic inventory. From the data model and the implementation it looks like explicit IPAM access is not provided by netbox.netbox.nb_inventory. But my question would be if you really need that as the information relevant to a device is included in the inventory of that device (VLAN names, VIDs, IP addresses of the interfaces). Also custom fields of devices are included. But I don’t need an answer to that as my use case is not a complex network. I just wanted to provide input how the review can be implemented with the official inventory plugin.

Thanks again for sharing all this work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants