nutanix / nutanix.ansible

Official Nutanix Ansible collections
GNU General Public License v3.0
67 stars 36 forks source link

[Imprv] add functionality constructed to module inventory #235

Closed peshay closed 2 years ago

peshay commented 2 years ago

Describe the request Enable Constructed Features for the inventory plugin

Current behaviour There is no way to create additional groups from the inventory plugin.

Expected behaviour Add constructed functionality to the plugin, so it is possible to create additional vars and groups based on Jinja2.

For example

plugin: nutanix.ncp.ntnx_prism_vm_inventory
groups:
  nutanix: true
keyed_groups:
  # group for customer name
  - prefix: ""
    separator: ''
    key: "inventory_hostname | regex_replace('([a-zA-Z0-9]+)-([a-zA-Z0-9]+)-([a-zA-Z0-9]+)', '\\1')"
  # group for service name
  - prefix: ""
    separator: ''
    key: "inventory_hostname | regex_replace('([a-zA-Z0-9]+)-([a-zA-Z0-9]+)-([a-zA-Z]+)[0-9]*', '\\3')"
  # group for environemnt name
  - prefix: ""
    separator: ''
    key: "inventory_hostname | regex_replace('([a-zA-Z0-9]+)-([a-zA-Z0-9]+)-([a-zA-Z0-9]+)', '\\2')"
  # group for customer environemnt name
  - prefix: ""
    separator: ''
    key: "inventory_hostname | regex_replace('([a-zA-Z0-9]+)-([a-zA-Z0-9]+)-([a-zA-Z0-9]+)', '\\1_\\2')"

Here is a pull request to add the requested functionality: https://github.com/nutanix/nutanix.ansible/issues/232

bhati-pradeep commented 2 years ago

@peshay I am looking into it. One use-case enhancement we need to add more here is the grouping using categories of vm.

bhati-pradeep commented 2 years ago

Released in v1.7.0