nutanix / nutanix.ansible

Official Nutanix Ansible collections
GNU General Public License v3.0
61 stars 34 forks source link

Add templating support in some inventory field #463

Open Gianlu opened 5 months ago

Gianlu commented 5 months ago

Hi, I submit this PR in order to add Jinja templating support in inventory for these fields:

I think that it can be very useful based on my scenarios. You already have the support for environment variables but I have scenarios where I have to query 2 (or more) Prism Central because I have to target distributed applications (I have a PC for site). In my configuration:

./inventory
├── 00_pc01.nutanix.yaml
├── 00_pc02.nutanix.yaml
└── 99_final.yml

in 00_pc01.nutanix.yaml I have:

plugin: nutanix.ncp.ntnx_prism_vm_inventory
nutanix_hostname: "{{ lookup('ansible.builtin.env', 'PC_1_HOSTNAME') }}"
nutanix_username: "{{ lookup('ansible.builtin.env', 'PC_1_USERNAME') }}"
nutanix_password: "{{ lookup('ansible.builtin.env', 'PC_1_PASSWORD') }}"

When I run

$ ansible-inventory --list -y --output test.yml

I have PCs Inventory merged.

I hope it hepls

bye