63
63
- name: VALIDATE_CERTS
64
64
notes: "null"
65
65
requirements: "null"
66
+ extends_documentation_fragment:
67
+ - constructed
66
68
"""
67
69
68
70
import json # noqa: E402
69
71
import tempfile # noqa: E402
70
72
71
- from ansible .plugins .inventory import BaseInventoryPlugin # noqa: E402
73
+ from ansible .plugins .inventory import BaseInventoryPlugin , Constructable # noqa: E402
72
74
73
75
from ..module_utils .prism import vms # noqa: E402
74
76
@@ -89,7 +91,7 @@ def jsonify(self, data):
89
91
return json .dumps (data )
90
92
91
93
92
- class InventoryModule (BaseInventoryPlugin ):
94
+ class InventoryModule (BaseInventoryPlugin , Constructable ):
93
95
"""Nutanix VM dynamic invetory module for ansible"""
94
96
95
97
NAME = "nutanix.ncp.ntnx_prism_vm_inventory"
@@ -117,6 +119,8 @@ def parse(self, inventory, loader, path, cache=True):
117
119
self .nutanix_port = self .get_option ("nutanix_port" )
118
120
self .data = self .get_option ("data" )
119
121
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' )
120
124
121
125
module = Mock_Module (
122
126
self .nutanix_hostname ,
@@ -172,3 +176,12 @@ def parse(self, inventory, loader, path, cache=True):
172
176
173
177
for key , value in entity ["status" ]["resources" ].items ():
174
178
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