From 90e9969fb55c6fed0597e8b4d530efe925a8fb0d Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Fri, 17 Nov 2017 01:09:52 +0000 Subject: [PATCH] VMware: handle error for MarkAsTemplate API (#32968) This fix adds exception handling for 'MarkAsTemplate' API in vmware_guest module. Signed-off-by: Abhijeet Kasurde --- lib/ansible/modules/cloud/vmware/vmware_guest.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index 9a22f784eec..c4d7858e3ea 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -317,7 +317,7 @@ import time HAS_PYVMOMI = False try: import pyVmomi - from pyVmomi import vim + from pyVmomi import vim, vmodl HAS_PYVMOMI = True except ImportError: @@ -1456,7 +1456,11 @@ class PyVmomiHelper(PyVmomi): # Mark VM as Template if self.params['is_template'] and not self.current_vm_obj.config.template: - self.current_vm_obj.MarkAsTemplate() + try: + self.current_vm_obj.MarkAsTemplate() + except vmodl.fault.NotSupported as e: + self.module.fail_json(msg="Failed to mark virtual machine [%s] " + "as template: %s" % (self.params['name'], e.msg)) change_applied = True # Mark Template as VM