Replies: 1 comment 2 replies
-
How you model this is going to depend a bit on your topology, but if VLANs are a Site specific thing then associating the VLANs with a Site will allow you to query for all VLANs for a Site to then apply to the Devices when you template the config. If tying VLANs to Sites isn't the right model for your topology then you may need to put the VLANs in VLAN Groups and tie the groups to a Regions or Site Groups, which are two ways to organize Sites, a Site can be associated with one Region and one Site Group, and those are hierarchical so you have two overlapping ways to organize. Another way to do it is if you always have VLANs presented on access/tagged interfaces, and don't have trunking config for VLANs that do not exist on the device (eg. trunking is not not dynamic or 2-4095 or whatever) then you can query all the interfaces associated with a device and fetch all untagged_vlan and tagged_vlans records and use that as your list, so when a VLAN is added to an interface the template can automatically add the instance. Here is an ansible way to scrape all the vlans using nb_lookup netbox_interfaces: "{{ query('netbox.netbox.nb_lookup', 'interfaces', api_filter=interface_api_filter, api_endpoint=netbox_api, token=netbox_token) | map(attribute='value') | list }}"
tagged_vlans: "{{ netbox_interfaces | selectattr('tagged_vlans') | map(attribute='tagged_vlans') | flatten }}"
untagged_vlans: "{{ netbox_interfaces | selectattr('untagged_vlan') | map(attribute='untagged_vlan') | flatten }}"
ansible_vlans: "{{ tagged_vlans + untagged_vlans }}"
vlans: "{{ ansible_vlans | unique | sort(attribute='vid') }}"
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
HI all,
Im trying out the netbox.nb_inventory module to extract device information/fact for our Cisco devices.
Im not quite sure how to get layer2 vlans out of netbox and into ansible. since the vlans are not directly associated with a device but with a sites instead I do not get the vlan info from netbox.
I obvoiusly get any layer3 interfaces that are SVI, but for any "layer2" vlans, I dont get anything. Looking at the API URLs that are being fetched, it looks like ipam/vlans are not even considered.
So the question is: how do I get the layer2 vlans for a site and associate with the device via the site-name
Any takers?
Esben
Beta Was this translation helpful? Give feedback.
All reactions