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 0000000000..81e613e4b9 --- /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 5d7c472c78..e1a4d56a21 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: