From 570cc7c2d9513a32ef98a4dab0a1cd8cb0813011 Mon Sep 17 00:00:00 2001 From: Mario Lenz Date: Mon, 25 Jul 2022 14:39:27 +0200 Subject: [PATCH] Fix NoneType object has no attribute datastoreUrl for inaccessible VMs (#1408) vmware_vm_info: Fix NoneType object has no attribute datastoreUrl for inaccessible VMs SUMMARY The module fails on inaccessible VMs with 'NoneType' object has no attribute 'datastoreUrl'. Fixes #1407 ISSUE TYPE Bugfix Pull Request COMPONENT NAME vmware_vm_info ADDITIONAL INFORMATION --- changelogs/fragments/1407-vmware_vm_info-inaccessible_vm.yml | 2 ++ plugins/modules/vmware_vm_info.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/1407-vmware_vm_info-inaccessible_vm.yml diff --git a/changelogs/fragments/1407-vmware_vm_info-inaccessible_vm.yml b/changelogs/fragments/1407-vmware_vm_info-inaccessible_vm.yml new file mode 100644 index 000000000..32ecf4bf4 --- /dev/null +++ b/changelogs/fragments/1407-vmware_vm_info-inaccessible_vm.yml @@ -0,0 +1,2 @@ +bugfixes: + - vmware_vm_info - Fix 'NoneType' object has no attribute 'datastoreUrl' for inaccessible VMs (https://github.com/ansible-collections/community.vmware/issues/1407). diff --git a/plugins/modules/vmware_vm_info.py b/plugins/modules/vmware_vm_info.py index 0a97b0a4f..7dadd2ef4 100644 --- a/plugins/modules/vmware_vm_info.py +++ b/plugins/modules/vmware_vm_info.py @@ -351,8 +351,9 @@ def get_virtual_machines(self): datacenter = get_parent_datacenter(vm) datastore_url = list() datastore_attributes = ('name', 'url') - if vm.config.datastoreUrl: - for entry in vm.config.datastoreUrl: + vm_datastore_urls = _get_vm_prop(vm, ('config', 'datastoreUrl')) + if vm_datastore_urls: + for entry in vm_datastore_urls: datastore_url.append({key: getattr(entry, key) for key in dir(entry) if key in datastore_attributes}) virtual_machine = { "guest_name": summary.config.name,