From bb50c65769bacba9cbf7c7461e497f31bd0d6560 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 17 Apr 2018 16:20:46 +0530 Subject: [PATCH] VMware: handle permission denied while reading facts (#38868) This fix adds exception handling which is raised when user does not have correct set of permissions/privileges to read virtual machine facts especially host system configuration. Fixes: #37056 Signed-off-by: Abhijeet Kasurde (cherry picked from commit efc3f4f824402fd7033c53c954a57b693b61f76d) --- .../fragments/37056-vmware_guest_no_permission.yaml | 2 ++ lib/ansible/module_utils/vmware.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/37056-vmware_guest_no_permission.yaml diff --git a/changelogs/fragments/37056-vmware_guest_no_permission.yaml b/changelogs/fragments/37056-vmware_guest_no_permission.yaml new file mode 100644 index 00000000000..994272420b8 --- /dev/null +++ b/changelogs/fragments/37056-vmware_guest_no_permission.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Adds exception handling which is raised when user does not have correct set of permissions/privileges to read virtual machine facts. diff --git a/lib/ansible/module_utils/vmware.py b/lib/ansible/module_utils/vmware.py index a76c219a0f5..e9ad9472cb5 100644 --- a/lib/ansible/module_utils/vmware.py +++ b/lib/ansible/module_utils/vmware.py @@ -305,8 +305,14 @@ def gather_vm_facts(content, vm): # facts that may or may not exist if vm.summary.runtime.host: - host = vm.summary.runtime.host - facts['hw_esxi_host'] = host.summary.config.name + try: + host = vm.summary.runtime.host + facts['hw_esxi_host'] = host.summary.config.name + except vim.fault.NoPermission: + # User does not have read permission for the host system, + # proceed without this value. This value does not contribute or hamper + # provisioning or power management operations. + pass if vm.summary.runtime.dasVmProtection: facts['hw_guest_ha_state'] = vm.summary.runtime.dasVmProtection.dasProtected