From 487f2f25ced8337ae928c16333be3f1731361666 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Fri, 2 Nov 2018 13:40:06 +0530 Subject: [PATCH] VMware: Handle exception for no snapshot while cloning (#47924) Handle exception when there is no snapshot available in virtual machine or template while cloning using vmware_guest. Fixes: #47920 Signed-off-by: Abhijeet Kasurde --- .../fragments/47920-vmware_guest-handle_no_root_snapshot.yaml | 2 ++ lib/ansible/modules/cloud/vmware/vmware_guest.py | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 changelogs/fragments/47920-vmware_guest-handle_no_root_snapshot.yaml diff --git a/changelogs/fragments/47920-vmware_guest-handle_no_root_snapshot.yaml b/changelogs/fragments/47920-vmware_guest-handle_no_root_snapshot.yaml new file mode 100644 index 00000000000..81e613e4b96 --- /dev/null +++ b/changelogs/fragments/47920-vmware_guest-handle_no_root_snapshot.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Handle exception when there is no snapshot available in virtual machine or template while cloning using vmware_guest. diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index 5d7c472c78a..e1a4d56a21c 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -2073,6 +2073,8 @@ class PyVmomiHelper(PyVmomi): clonespec.customization = self.customspec if snapshot_src is not None: + if vm_obj.snapshot is None: + self.module.fail_json(msg="No snapshots present for virtual machine or template [%(template)s]" % self.params) snapshot = self.get_snapshots_by_name_recursively(snapshots=vm_obj.snapshot.rootSnapshotList, snapname=snapshot_src) if len(snapshot) != 1: