nutanix.ansible icon indicating copy to clipboard operation
nutanix.ansible copied to clipboard

Hostnames key support in inventory

Open Gianlu opened this issue 1 year ago • 4 comments

Hi, I added the support of the "hostnames" key in inventory definition. In the hostname key, you may specify a Jinja2 template that modifies the ansible_hostname. For example, I use this option in order to convert vm name in lower case.

---
plugin: 'nutanix.ncp.ntnx_prism_vm_inventory'
data:
  offset: 0
  length: 3000
hostnames:
  - status.name | lower

With this patch you have to specify the property as returned by Prism Central REST API; perhaps it will be more simple if you use the object you add to ansible inventory but it seems a bit of refactoring is needed.

Hope it helps,

Thanks

Gianlu avatar Sep 23 '23 16:09 Gianlu

@Gianlu Thank you for the contribution. I tried locally and its a good usecase.

@Gevorg-Khachatryan-97 Please can you verify this once :

  1. Check if we can pick vm inventory object directly instead of rest api response. Instead of "status.name" if we can use "name".

Currently moving it to 1.9.1 -> 1.9.2, as we are near to release.

Thanks.

bhati-pradeep avatar Oct 30 '23 20:10 bhati-pradeep

@Gianlu / @Gevorg-Khachatryan-97 Can you please raise a Github issue with reference docs. Thanks

bhati-pradeep avatar Oct 30 '23 20:10 bhati-pradeep

@Gianlu Can we can add more examples for this ? Inside examples folder.

Thanks

bhati-pradeep avatar Oct 30 '23 20:10 bhati-pradeep

Hi @bhati-pradeep, I'm sorry for the delay. I pushed a commit where I modify your inventory example with the hostnames modification. I hope we can target 1.9.2 release. Let me know if you want further modifications.

Gianlu avatar Feb 08 '24 16:02 Gianlu