Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/inventory_issue#232 #233

Merged
merged 1 commit into from
Sep 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)