Skip to content

Commit 56045d5

Browse files
peshayAndreas Hubert
authored and
Andreas Hubert
committed
feat/inventory_issue#232
1 parent f4174ea commit 56045d5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

plugins/inventory/ntnx_prism_vm_inventory.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@
6363
- name: VALIDATE_CERTS
6464
notes: "null"
6565
requirements: "null"
66+
extends_documentation_fragment:
67+
- constructed
6668
"""
6769

6870
import json # noqa: E402
6971
import tempfile # noqa: E402
7072

71-
from ansible.plugins.inventory import BaseInventoryPlugin # noqa: E402
73+
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable # noqa: E402
7274

7375
from ..module_utils.prism import vms # noqa: E402
7476

@@ -89,7 +91,7 @@ def jsonify(self, data):
8991
return json.dumps(data)
9092

9193

92-
class InventoryModule(BaseInventoryPlugin):
94+
class InventoryModule(BaseInventoryPlugin, Constructable):
9395
"""Nutanix VM dynamic invetory module for ansible"""
9496

9597
NAME = "nutanix.ncp.ntnx_prism_vm_inventory"
@@ -117,6 +119,8 @@ def parse(self, inventory, loader, path, cache=True):
117119
self.nutanix_port = self.get_option("nutanix_port")
118120
self.data = self.get_option("data")
119121
self.validate_certs = self.get_option("validate_certs")
122+
# Determines if composed variables or groups using nonexistent variables is an error
123+
strict = self.get_option('strict')
120124

121125
module = Mock_Module(
122126
self.nutanix_hostname,
@@ -172,3 +176,12 @@ def parse(self, inventory, loader, path, cache=True):
172176

173177
for key, value in entity["status"]["resources"].items():
174178
self.inventory.set_variable(vm_name, key, value)
179+
180+
# Add variables created by the user's Jinja2 expressions to the host
181+
self._set_composite_vars(self.get_option('compose'), entity["status"]["resources"], vm_name, strict=strict)
182+
183+
# The following two methods combine the provided variables dictionary with the latest host variables
184+
# Using these methods after _set_composite_vars() allows groups to be created with the composed variables
185+
self._add_host_to_composed_groups(self.get_option('groups'), entity["status"]["resources"], vm_name, strict=strict)
186+
self._add_host_to_keyed_groups(self.get_option('keyed_groups'), entity["status"]["resources"], vm_name, strict=strict)
187+

0 commit comments

Comments
 (0)