community.vmware
community.vmware copied to clipboard
Cannot use "resourcePool" in "properties" of vm_inventory plugin
SUMMARY
In wanting to use the latest AWX version (19.2.2), with the latest VMware inventory plugin, I cannot use "resourcePool.*" in properties.
If you place "resourcePool" itself as a property, what is returned is the object's string representation itself.
It would appear that the vim.ResourcePool object is not being teased apart into a hash so that it is usable for inventory variables.
ISSUE TYPE
- Bug Report
COMPONENT NAME
name: vmware_vm_inventory
plugin_type: inventory
ANSIBLE VERSION
AWX container version: awx:19.2.2
AWX execution environment: awx-ee:0.5.0
bash-4.4$ ansible --version
ansible [core 2.11.2.post0]
config file = None
configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.8.6 (default, Jan 29 2021, 17:38:16) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
jinja version = 2.10.3
libyaml = True
COLLECTION VERSION
bash-4.4$ ansible-galaxy collection list community.vmware
# /usr/share/ansible/collections/ansible_collections
Collection Version
---------------- -------
community.vmware 1.11.0
CONFIGURATION
Defaults.
bash-4.4$ ansible-config dump --only-changed
bash-4.4$
OS / ENVIRONMENT
Running AWX under minikube, per standard instructions with the latest AWX Operator.
STEPS TO REPRODUCE
Set up AWX with a vCenter source for a smart inventory, and use the following as the Source Variables (as JSON):
{
"properties": [
"config",
"resourcePool"
]
}
Save the source and run a sync.
EXPECTED RESULTS
Select a VM from the Hosts in your AWX inventory that was just updated from the sync. Look at the variables. See that resourcePool is a hash, just like config. I expect that it would be populated as described in the documentation at https://docs.ansible.com/ansible/latest/scenario_guides/vmware_scenarios/vmware_inventory_vm_attributes.html#resourcepool-vim-resourcepool
Specifically, to populate those variables such that they can be used for a "keyed_group".
{
"config": {
"instanceUuid": "placeholder",
"name": "placeholder",
"uuid": "placeholder"
...
},
...
"resourcePool": {
"summary": "placeholder",
"vm": "placeholder",
...
},
...
}
ACTUAL RESULTS
Instead of a hash, resourcePool comes back as a printed string representation of the vim object.
{
"config": {
"instanceUuid": "placeholder",
"name": "placeholder",
"uuid": "placeholder"
...
},
...
"resourcePool": "'vim.ResourcePool:resgroup-168471'",
...
}
Additionally, any attempt to use a property in the vCenter source to sync such as "resourcePool.name" results in a failed sync job and the error as follows:
ansible-inventory [core 2.11.2.post0]
config file = None
configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections:/usr/share/automation-controller/collections
executable location = /usr/local/bin/ansible-inventory
python version = 3.8.6 (default, Jan 29 2021, 17:38:16) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
jinja version = 2.10.3
libyaml = True
No config file found; using defaults
redirecting (type: inventory) ansible.builtin.vmware_vm_inventory to community.vmware.vmware_vm_inventory
[WARNING]: Invalid property name: resourcePool.summary
Parsed /runner/inventory/vmware_vm_inventory.yml inventory source with auto plugin
4.416 INFO Processing JSON output...
4.418 INFO Loaded 0 groups, 0 hosts
4.439 INFO Inventory import completed for vCenter Source in 0.0s
Files identified in the description: None
If these files are inaccurate, please update the component name section of the description or use the !component bot command.
@thehammeredone Thanks for reporting this issue.
When code calls VM properties - for config it returns
(vmodl.DynamicProperty) {
name = 'config',
val = (vim.vm.ConfigInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
changeVersion = '2021-07-12T11:56:30.108869Z',
modified = 1970-01-01T00:00:00Z,
name = 'VM1',
and
for resourcePool it returns
(vmodl.DynamicProperty) {
name = 'resourcePool',
val = 'vim.ResourcePool:resgroup-9'
}
This is the reason, you can access config as a dict whereas resourcePool is failing.
I totally agree with your findings. I am still trying to find a way to represent resourcePool name.
If it helps with the investigation, when I was playing around with PowerShell to see what objects I could get a hold of, I ran across this:
PS C:\Users\user> $allVMs[1].ExtensionData.ResourcePool
Type Value
---- -----
ResourcePool resgroup-237038
PS C:\Users\user> $allVMs[1].ResourcePool
Name CpuSharesL CpuReserva CpuLimitMH MemSharesL MemReservationG MemLimitGB
evel tionMHz z evel B
---- ---------- ---------- ---------- ---------- --------------- ----------
Placeholder Normal 0 -1 Normal 0.000 -1.000
Seems that whereas with other objects you get MORE data by referencing them through the "ExtensionData" portion of the VM object returned by a Get-VM call, the resource pool object is the opposite, only containing the string represetntation of the object, vs. the full object itself.
@thehammeredone Yes, this is the same case with Pyvmomi API. API is returning string instead of the object itself.
@thehammeredone I am not sure how to solve this issue. Either we can write our own logic to retrieve the information about the resource pool associate with the VM or ask Pyvmomi to return the object instead of the string value of the resource pool.
@sky-joker @mariolenz @goneri What do you think? Thanks in advance.
Also affected by this issue