nutanix / nutanix.ansible

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

[Feat] Develop ansible module for inventory #232

Closed peshay closed 2 years ago

peshay commented 2 years ago

Requirements:

Todo:

peshay commented 2 years ago

Example: I have a name schema to name VMs, based on this with my PR it is possible to put hosts directly in specific groups, based on the inventory_hostname:

plugin: nutanix.ncp.ntnx_prism_vm_inventory
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')"

Further examples can be found here in the Ansible Documentation

peshay commented 2 years ago

FYI I just changed/overwritten my original PR. I just did a small change, because in the beginning I added additional dictionary and vm_name to the variables, but since vm_name == inventory_hostname it is not needed and therefore now more simpler PR.

peshay commented 2 years ago

Sorry, this was opened as NEW Feature, but instead I want an enhancement of the existing inventory. My apologies for the confusion, I close this one in favour of https://github.com/nutanix/nutanix.ansible/issues/235