netbox-community / ansible_modules

NetBox modules for Ansible using Ansible Collections
GNU General Public License v3.0
330 stars 212 forks source link

[Feature]: Enable lowercase output direct into inventory #760

Open chrisvanmeer opened 2 years ago

chrisvanmeer commented 2 years ago

NetBox version

v3.1.10

Feature type

Change to existing Plugin

Proposed functionality

Could it be possible to declare a parameter in the inventory YAML file to allow for lowercase output of the device / vm names? And also convert the spaces to dashes (-) so we could safely refer to a inventory name without having to convert it in the play / role.

All the rest of the fields already map to the slug part of the object, which is by default lowercase and eliminates all of the spaces by converting it to dashes.

Use case

$ cat netbox-inventory.yml

plugin: netbox.netbox.nb_inventory
api_endpoint: https://netbox.external.fqdn
group_names_raw: true
group_by:
  - tags
query_filters:
  - tag: lowercase

$ ansible-inventory --graph -i netbox-inventory.yml

@all:
  |--@lowercase:
  |  |--DeViCE 1
  |  |--Device 2 name
  |--@ungrouped:

Proposed output

@all:
  |--@lowercase:
  |  |--device-1
  |  |--device-2-name
  |--@ungrouped:

External dependencies

No response

ryanmerolle commented 2 years ago

It could be easier for some sort of tag_slug query filter since slugs are lowercase.

chrisvanmeer commented 2 years ago

Sounds good to me.

ryanmerolle commented 2 years ago

Feel free to submit a PR and we'd be happy to help you guide and troubleshoot time permitting.