nutanix / nutanix.ansible

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

Hostnames key support in inventory #399

Open Gianlu opened 11 months ago

Gianlu commented 11 months ago

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

bhati-pradeep commented 10 months ago

@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 commented 10 months ago

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

bhati-pradeep commented 10 months ago

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

Thanks

Gianlu commented 7 months ago

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.