From f21b41d3aa3cfea912b623e72b8321b0dde7f7c7 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Fri, 27 Aug 2021 19:04:00 +0200 Subject: [PATCH] Fixed incorrect VMID: cloning to an existing VM (#3266) (#3281) * Fixed incorrect VMID: cloning to an existing VM During a cloning operation, if the destination VM already exists the VMID returned is not correct. The VMID returned should be that of the destination VM and not that of the source VM (consistent with line 1230). A playbook that relies on the returned VMID, for example, to perform other operations on the destination VM, will not work properly if it is unexpectedly interrupted. * Add files via upload * moved 3266-vmid-existing-target-clone.yml to changelogs/fragments/ replaced line separator CRLF -> LF * storing vmid list in variable to avoid multiple API calls (cherry picked from commit 4e2d4e3c68c078e1b04ef69bc9a4a5f8588f3b7a) Co-authored-by: Atlas974 <43972908+Atlas974@users.noreply.github.com> --- changelogs/fragments/3266-vmid-existing-target-clone.yml | 3 +++ plugins/modules/cloud/misc/proxmox_kvm.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/3266-vmid-existing-target-clone.yml diff --git a/changelogs/fragments/3266-vmid-existing-target-clone.yml b/changelogs/fragments/3266-vmid-existing-target-clone.yml new file mode 100644 index 0000000000..5ff59f5311 --- /dev/null +++ b/changelogs/fragments/3266-vmid-existing-target-clone.yml @@ -0,0 +1,3 @@ +bugfixes: + - proxmox_kvm - clone operation should return the VMID of the target VM and not that of the source VM. + This was failing when the target VM with the chosen name already existed (https://github.com/ansible-collections/community.general/pull/3266). \ No newline at end of file diff --git a/plugins/modules/cloud/misc/proxmox_kvm.py b/plugins/modules/cloud/misc/proxmox_kvm.py index 6f53a7bfc0..550cd4dad7 100644 --- a/plugins/modules/cloud/misc/proxmox_kvm.py +++ b/plugins/modules/cloud/misc/proxmox_kvm.py @@ -1201,8 +1201,9 @@ def main(): module.fail_json(vmid=vmid, msg='VM with vmid = %s does not exist in cluster' % vmid) # Ensure the choosen VM name doesn't already exist when cloning - if get_vmid(proxmox, name): - module.exit_json(changed=False, vmid=vmid, msg="VM with name <%s> already exists" % name) + existing_vmid = get_vmid(proxmox, name) + if existing_vmid: + module.exit_json(changed=False, vmid=existing_vmid[0], msg="VM with name <%s> already exists" % name) # Ensure the choosen VM id doesn't already exist when cloning if get_vm(proxmox, newid):