diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index a32a24da44..1930a89ae6 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -2265,42 +2265,50 @@ class vmware(PluginFileInjector): def inventory_as_dict(self, inventory_update, private_data_dir): ret = super(vmware, self).inventory_as_dict(inventory_update, private_data_dir) ret['strict'] = False - ret['properties'] = [ - "name", + # Documentation of props, see + # https://github.com/ansible/ansible/blob/devel/docs/docsite/rst/scenario_guides/vmware_scenarios/vmware_inventory_vm_attributes.rst + UPPERCASE_PROPS = [ "ansible_ssh_host", "ansible_host", "ansible_uuid", - "availablefield", - "capability", # nested properties - "config", # nested properties - "configissue", - "configstatus", - "customvalue", + "availableField", # optional? + "configIssue", # optional? + "configStatus", # optional? + "customValue", # optional? "datastore", - "effectiverole", - "guest", # nested properties - "guestheartbeatstatus", - "layout", - "layoutex", + "effectiveRole", # optional? + "guestHeartbeatStatus", # optonal? + "layout", # optional? + "layoutEx", # optional? "name", "network", - "overallstatus", - "parentvapp", + "overallStatus", # optional? + "parentVApp", # optional? "permission", - "recenttask", - "resourcepool", - "rootsnapshot", - "runtime", # nested properties - "snapshot", - "storage", # nested properties - "summary", # repeat of other properties + "recentTask", # optional? + "resourcePool", + "rootSnapshot", # optional? + "snapshot", # optional "tag", - "triggeredalarmstate", - "value", + "triggeredAlarmState", + "value" ] - # ret['properties'] = ["all"] # causes UnknownWsdlTypeError exception - ret['with_nested_properties'] = True - ret['property_name_format'] = 'lower_case' + NESTED_PROPS = [ + "capability", + "config", + "guest", + "runtime", + "storage", + "summary", # repeat of other properties + ] + ret['properties'] = UPPERCASE_PROPS + NESTED_PROPS + ret['compose'] = {} + for prop in UPPERCASE_PROPS: + if prop == prop.lower(): + continue + ret['compose'][prop.lower()] = prop + # ret['with_nested_properties'] = True # only dacrystal/topic/vmware-inventory-plugin-enhancements + # ret['property_name_format'] = 'lower_case' # only dacrystal/topic/vmware-inventory-plugin-property-format # process custom options vmware_opts = dict(inventory_update.source_vars_dict.items()) @@ -2320,16 +2328,18 @@ class vmware(PluginFileInjector): host_pattern = vmware_opts.get('host_pattern') # not working in script if host_pattern: - pass # does not appear to have an option for this + stripped_hp = host_pattern.replace('{', '').replace('}', '').strip() # make best effort + ret['compose']['ansible_host'] = stripped_hp + ret['compose']['ansible_ssh_host'] = stripped_hp host_filters = vmware_opts.get('host_filters') if host_filters: - ret.setdefault('host_filters', []) + ret.setdefault('filters', []) for hf in host_filters.split(','): striped_hf = hf.replace('{', '').replace('}', '').strip() # make best effort if not striped_hf: continue - ret['host_filters'].append(striped_hf) + ret['filters'].append(striped_hf) groupby_patterns = vmware_opts.get('groupby_patterns') if groupby_patterns: diff --git a/awx/main/tests/data/inventory/plugins/vmware/files/vmware_vm_inventory.yml b/awx/main/tests/data/inventory/plugins/vmware/files/vmware_vm_inventory.yml index 18b96b9e78..36796f1779 100644 --- a/awx/main/tests/data/inventory/plugins/vmware/files/vmware_vm_inventory.yml +++ b/awx/main/tests/data/inventory/plugins/vmware/files/vmware_vm_inventory.yml @@ -1,43 +1,55 @@ -host_filters: -- config.name == "only_my_server" -- somevar == "bar" +compose: + availablefield: availableField + configissue: configIssue + configstatus: configStatus + customvalue: customValue + effectiverole: effectiveRole + guestheartbeatstatus: guestHeartbeatStatus + layoutex: layoutEx + overallstatus: overallStatus + parentvapp: parentVApp + recenttask: recentTask + resourcepool: resourcePool + rootsnapshot: rootSnapshot + triggeredalarmstate: triggeredAlarmState +filters: +- config.zoo == "DC0_H0_VM0" +hostnames: +- config.foo keyed_groups: -- key: fouo +- key: config.asdf prefix: '' separator: '' plugin: community.vmware.vmware_vm_inventory properties: -- name - ansible_ssh_host - ansible_host - ansible_uuid -- availablefield -- capability -- config -- configissue -- configstatus -- customvalue +- availableField +- configIssue +- configStatus +- customValue - datastore -- effectiverole -- guest -- guestheartbeatstatus +- effectiveRole +- guestHeartbeatStatus - layout -- layoutex +- layoutEx - name - network -- overallstatus -- parentvapp +- overallStatus +- parentVApp - permission -- recenttask -- resourcepool -- rootsnapshot -- runtime +- recentTask +- resourcePool +- rootSnapshot - snapshot +- tag +- triggeredAlarmState +- value +- capability +- config +- guest +- runtime - storage - summary -- tag -- triggeredalarmstate -- value -property_name_format: lower_case strict: false -with_nested_properties: true diff --git a/awx/main/tests/data/inventory/scripts/vmware/files/file_reference b/awx/main/tests/data/inventory/scripts/vmware/files/file_reference index 5282c2db71..56b3c1c920 100644 --- a/awx/main/tests/data/inventory/scripts/vmware/files/file_reference +++ b/awx/main/tests/data/inventory/scripts/vmware/files/file_reference @@ -5,6 +5,7 @@ username = fooo password = fooo server = https://foo.invalid base_source_var = value_of_var -host_filters = {{ config.name == "only_my_server" }},{{ somevar == "bar"}} -groupby_patterns = fouo +alias_pattern = {{ config.foo }} +host_filters = {{ config.zoo == "DC0_H0_VM0" }} +groupby_patterns = {{ config.asdf }} diff --git a/awx/main/tests/functional/test_inventory_source_injectors.py b/awx/main/tests/functional/test_inventory_source_injectors.py index 50510e3c16..c3c70d0c4a 100644 --- a/awx/main/tests/functional/test_inventory_source_injectors.py +++ b/awx/main/tests/functional/test_inventory_source_injectors.py @@ -53,6 +53,9 @@ INI_TEST_VARS = { 'rhv': {}, # there are none 'tower': {}, # there are none 'vmware': { + 'alias_pattern': "{{ config.foo }}", + 'host_filters': '{{ config.zoo == "DC0_H0_VM0" }}', + 'groupby_patterns': "{{ config.asdf }}", # setting VMWARE_VALIDATE_CERTS is duplicated with env var }, 'azure_rm': {