diff --git a/.gitignore b/.gitignore index b04e3045..98ef2a26 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ nutanix-ncp-* +__pycache__/ \ No newline at end of file diff --git a/examples/inventory/templating_1_nutanix.yaml b/examples/inventory/templating_1_nutanix.yaml new file mode 100644 index 00000000..a54014e1 --- /dev/null +++ b/examples/inventory/templating_1_nutanix.yaml @@ -0,0 +1,13 @@ +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') }}" +validate_certs: false +data: {"offset": 0, "length": 1000} +groups: + group_1: "'' in name" + group_2: "''==name" +keyed_groups: + - prefix: "host" + separator: ':' + key: "ansible_host" \ No newline at end of file diff --git a/examples/inventory/templating_2_nutanix.yaml b/examples/inventory/templating_2_nutanix.yaml new file mode 100644 index 00000000..a6c7a0f6 --- /dev/null +++ b/examples/inventory/templating_2_nutanix.yaml @@ -0,0 +1,13 @@ +plugin: nutanix.ncp.ntnx_prism_vm_inventory +nutanix_hostname: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=path/to/pc/secret:hostname') }}" +nutanix_username: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=path/to/pc/secret:username') }}" +nutanix_password: "{{ lookup('community.hashi_vault.hashi_vault', 'secret=path/to/pc/secret:password') }}" +validate_certs: false +data: {"offset": 0, "length": 1000} +groups: + group_1: "'' in name" + group_2: "''==name" +keyed_groups: + - prefix: "host" + separator: ':' + key: "ansible_host" \ No newline at end of file diff --git a/plugins/inventory/ntnx_prism_vm_inventory.py b/plugins/inventory/ntnx_prism_vm_inventory.py index 29cc6355..246c4697 100644 --- a/plugins/inventory/ntnx_prism_vm_inventory.py +++ b/plugins/inventory/ntnx_prism_vm_inventory.py @@ -24,25 +24,33 @@ required: true choices: ['ntnx_prism_vm_inventory', 'nutanix.ncp.ntnx_prism_vm_inventory'] nutanix_hostname: - description: Prism central hostname or IP address + description: + - Prism central hostname or IP address + - Accepts Jinja to template the value required: true type: str env: - name: NUTANIX_HOSTNAME nutanix_username: - description: Prism central username + description: + - Prism central username + - Accepts Jinja to template the value required: true type: str env: - name: NUTANIX_USERNAME nutanix_password: - description: Prism central password + description: + - Prism central password + - Accepts Jinja to template the value required: true type: str env: - name: NUTANIX_PASSWORD nutanix_port: - description: Prism central port + description: + - Prism central port + - Accepts Jinja to template the value default: 9440 type: str env: @@ -122,6 +130,19 @@ def parse(self, inventory, loader, path, cache=True): # Determines if composed variables or groups using nonexistent variables is an error strict = self.get_option("strict") + if self.templar.is_template(self.nutanix_hostname): + self.nutanix_hostname=self.templar.template(variable=self.nutanix_hostname,disable_lookups=False) + + if self.templar.is_template(self.nutanix_username): + self.nutanix_username=self.templar.template(variable=self.nutanix_username,disable_lookups=False) + + if self.templar.is_template(self.nutanix_password): + self.nutanix_password=self.templar.template(variable=self.nutanix_password,disable_lookups=False) + + if self.templar.is_template(self.nutanix_port): + self.nutanix_port=self.templar.template(variable=self.nutanix_port,disable_lookups=False) + + module = Mock_Module( self.nutanix_hostname, self.nutanix_port,