Skip to content

Commit

Permalink
vmware_guest_info: Handle list in guest facts
Browse files Browse the repository at this point in the history
Handle list items in vSphere schema while handling facts in vmware_guest_info

Fixes: ansible-collections#33

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
  • Loading branch information
Akasurde committed Mar 5, 2020
1 parent f7d8a84 commit a132d09
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/33-vmware_guest_info_list_fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- Handle list items in vSphere schema while handling facts in vmware_guest_info (https://github.com/ansible-collections/vmware/issues/33).
8 changes: 7 additions & 1 deletion plugins/module_utils/vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,13 @@ def _extract(self, data, remainder):
result[remainder] = data[remainder]
return result
key, remainder = remainder.split('.', 1)
result[key] = self._extract(data[key], remainder)
if isinstance(data, list):
temp_ds = []
for i in range(len(data)):
temp_ds.append(self._extract(data[i][key], remainder))
result[key] = temp_ds
else:
result[key] = self._extract(data[key], remainder)
return result

def _jsonify(self, obj):
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/targets/vmware_guest_info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@
- "guest_info_0001['instance']['vimref'] is defined"
- "guest_info_0002b['instance']['overallStatus'] is not defined"

# https://github.com/ansible-collections/vmware/issues/33
- name: Get specific details about VM using the vsphere output schema
vmware_guest_info:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ dc1 }}"
uuid: "{{ vm1_uuid }}"
schema: vsphere
properties:
- config.hardware.device.deviceInfo.summary
register: guest_info_with_list

- debug:
var: guest_info_with_list

- assert:
that:
- "guest_info_with_list['instance']['config']['hardware']['device'] is defined"

# Testcase 0003: Get details about virtual machines without snapshots using UUID
- name: get empty list of snapshots from virtual machine using UUID
vmware_guest_info:
Expand Down

0 comments on commit a132d09

Please sign in to comment.