Skip to content

Update Netbox inventory plugin add region grouping, optional interfaces&vlans gathering, slug and prefix length #280

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

Closed
Akasurde opened this issue Jul 14, 2020 · 4 comments
Labels

Comments

@Akasurde
Copy link

From @Yannis100 on Aug 06, 2019 08:26

SUMMARY

Add sites groups as children in their respective region groups
Add 1 value to choose the length of the group name prefix (before the '_') and 1 to "minify" the suffix part (using slugs (or lowercase and change special chars (space, -) to underscore))
Add interfaces per host and vlans per site

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

Netbox inventory plugin

ADDITIONAL INFORMATION

Grouping by regions add sites as children of the group but currently add hosts too.
Interfaces and vlan gathering works, maybe not perfectly optimized?

Similar to use_slugs in nornir netbox inventory plugin
https://github.com/nornir-automation/nornir/blob/develop/nornir/plugins/inventory/netbox.py

For interfaces gathering, the following is a good example :
https://github.com/openfibernet/ansible-netbox-inventory/blob/master/netbox.py
or #59725

plugin: netbox
api_endpoint: https://netbox:443
validate_certs: False
config_context: True
token: xxx
vlans: True
interfaces: True
use_slugs: True
substr_group: 8
group_by:
  - device_roles
  - device_types
  - sites
  - platforms
  - tags
  - regions
query_filters:
  - role: SWA
  - platform: ios-xe
ansible-inventory --graph
@all:
  |--@platform_ios-xe:
  |  |--3850-SWA01
  |--@device_r_SWA:
  |  |--3850-SWA01
  |--@device_t_WS-C3650-48PD-S:
  |  |--3650-SWA01
…
  |--@device_t_WS-C3850-12X48U-S:
  |  |--3850-SWA01
…
  |--@regions_AMR:
  |  |--@sites_US-PHX:
  |  |--@sites_USATL04:
  |  |  |--3850-SWA01
  |  |--@sites_USPHX03:
  |  |  |--3650-SWA01
  |--@regions_APAC:
  |  |--@sites_INBLR01:
  |  |  |--3850-SWA01-1
  |--@regions_EMEA:
  |  |--@sites_CHZRH04:
  |--@tags_uat:
  |  |--3850-SWA01-1
  |--@ungrouped:

If a site is not assigned to a region, the plugin may fail

Copied from original issue: ansible/ansible#60124

@Akasurde
Copy link
Author

@Akasurde
Copy link
Author

From @Yannis100 on Aug 08, 2019 12:15

#53380
#53384
#59725

@DouglasHeriot
Copy link
Contributor

DouglasHeriot commented Jul 14, 2020

I worked on improving this pull request and have had some elements merged already:

Not yet done:

  • Inventory: Fetch VLANs, and attach to interfaces VLANs #205 - VLANs. If simply all site VLANs were attached to every host the inventory file would be huge and potentially impact performance. (The JSON output of ansible-inventory --list is already 20MB for our NetBox database!).

    • I propose doing it slightly differently - download all VLANs, but only include the additional information on interfaces that have the VLAN on them. This will also duplicate a lot of information (hundred of ports with the same VLAN), but might be less than the alternative.
  • slug prefix length - I personally haven't had a use for this so haven't worked on it (I don't mind long strings). Not sure what others think?

@FragmentedPacket
Copy link
Contributor

I'm going to close this issue in favor of #205 since most of these features have been implemented other than the VLANs and prefix length.

If other people find value in the slug prefix length than an issue and PR can be opened for it.

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

No branches or pull requests

3 participants