Skip to content

Commit

Permalink
feat/inventory_issue#232 (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
peshay authored Sep 14, 2022
1 parent b82b58d commit 9b808f5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions plugins/inventory/ntnx_prism_vm_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

0 comments on commit 9b808f5

Please sign in to comment.