diff --git a/plugins/inventory/ntnx_prism_vm_inventory.py b/plugins/inventory/ntnx_prism_vm_inventory.py index 43c0ba216..5151d739d 100644 --- a/plugins/inventory/ntnx_prism_vm_inventory.py +++ b/plugins/inventory/ntnx_prism_vm_inventory.py @@ -63,12 +63,14 @@ - name: VALIDATE_CERTS notes: "null" requirements: "null" + extends_documentation_fragment: + - constructed """ import json # noqa: E402 import tempfile # noqa: E402 -from ansible.plugins.inventory import BaseInventoryPlugin # noqa: E402 +from ansible.plugins.inventory import BaseInventoryPlugin, Constructable # noqa: E402 from ..module_utils.prism import vms # noqa: E402 @@ -89,7 +91,7 @@ def jsonify(self, data): return json.dumps(data) -class InventoryModule(BaseInventoryPlugin): +class InventoryModule(BaseInventoryPlugin, Constructable): """Nutanix VM dynamic invetory module for ansible""" NAME = "nutanix.ncp.ntnx_prism_vm_inventory" @@ -117,6 +119,8 @@ def parse(self, inventory, loader, path, cache=True): self.nutanix_port = self.get_option("nutanix_port") self.data = self.get_option("data") self.validate_certs = self.get_option("validate_certs") + # Determines if composed variables or groups using nonexistent variables is an error + strict = self.get_option('strict') module = Mock_Module( self.nutanix_hostname, @@ -172,3 +176,12 @@ def parse(self, inventory, loader, path, cache=True): for key, value in entity["status"]["resources"].items(): self.inventory.set_variable(vm_name, key, value) + + # Add variables created by the user's Jinja2 expressions to the host + self._set_composite_vars(self.get_option('compose'), entity["status"]["resources"], vm_name, strict=strict) + + # The following two methods combine the provided variables dictionary with the latest host variables + # Using these methods after _set_composite_vars() allows groups to be created with the composed variables + self._add_host_to_composed_groups(self.get_option('groups'), entity["status"]["resources"], vm_name, strict=strict) + self._add_host_to_keyed_groups(self.get_option('keyed_groups'), entity["status"]["resources"], vm_name, strict=strict) +