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 159968ce6e..25b29b369b 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):