ansible_modules
ansible_modules copied to clipboard
[Feature]: nb_inventory should have an option to fetch interfaces from all virtual-chassis members
NetBox version
v2.11.6
Feature type
Change to existing Module
Proposed functionality
Setting a boolean to true should have the nb_inventory module to pull all interfaces from a device (master + child chassis from a virtual-chassis member).
At the moment, only direct interfaces are fetched when pulling interfaces information using nb_inventory.
Pseudo-code logic:
if host is member of a virtual-chassis and virtual_chassis_all_interfaces == true then combine interfaces of all virtual-chassis members return the combined interfaces list
Use case
When doing automation of network equipment, we always target the "master/primary" chassis and all members interfaces are configured/checked through this master chassis.
We almost never target a child chassis.
Also, this change in behaviour would reproduce the Web GUI interface. In the web version of Netbox, the master/primary chassis contains all interfaces of the virtual-chassis, so we can easily see and edit information from that single view. When using the Ansible module, we can't do the same (behaviour is not consistent).
External dependencies
None that I can think of.
Maybe this will help others. Here is my current workaround.
I created a "mini-role" that only does this:
- Fetch virtual-chassis information to get the members.
- If the host is in a VC, I loop through all members except "self" to do steps 2a and 2b.
2a. I get all interfaces from the member (I register the API call to
api/dcim/interfaces/?device=member&limit=0
). 2b. I mergeinterfaces
with theregister.json.results
of 2a. - Et voilà! All interfaces are now in
interfaces
.
Would also love to see this functionality. We have several switch stacks which are modeled as a virtual chassis, and right now there's no easy way to deploy the complete interface configuration in one go, e.g. via the Ansible Cisco IOS roles.
@SteveRodrigue Would you be willing to share the code of your "mini-role"?
Would also love to see this functionality. We have several switch stacks which are modeled as a virtual chassis, and right now there's no easy way to deploy the complete interface configuration in one go, e.g. via the Ansible Cisco IOS roles.
@SteveRodrigue Would you be willing to share the code of your "mini-role"?
@hoalex Sharing the exact role would be a bit complicated. But here is the abstracted logic...
My current not optimal logic is:
- Register device information from netbox:
api/dcim/devices/?name={{ inventory_hostname }}
- Check if the device is member of a virtual_chassis: when registered_device['virtual_chassis']
- Get the virtual-chassis members:
api/dcim/devices/?virtual_chassis_id=XXXX
- For all chassis members (except the master) I do a loop...,
4a.I query Netbox for their interfaces:
api/dcim/interfaces/?limit=0&device=xxxx
4b. I simply merge all interfaces together into the master chassis.interfaces: {{ interfaces + member.interfaces }}
- Now, the list of interfaces of Master contains all interfaces.
To be honest, a streamlined logic would be this:
- Find the virtual_chassis ID from the master chassis.
- Get all interfaces for the virtual chassis:
api/dcim/interfaces/?limit=0&virtual_chassis_id=XXX
- Replace the master
interfaces
variable with the list of interfaces found in step 2.