diff --git a/changelogs/fragments/4945-fix-get_vm-int-parse-handling.yaml b/changelogs/fragments/4945-fix-get_vm-int-parse-handling.yaml new file mode 100644 index 0000000000..1a563f6c93 --- /dev/null +++ b/changelogs/fragments/4945-fix-get_vm-int-parse-handling.yaml @@ -0,0 +1,3 @@ +bugfixes: + - proxmox - fix error handling when getting VM by name when ``state=absent`` (https://github.com/ansible-collections/community.general/pull/4945). + - proxmox_kvm - fix error handling when getting VM by name when ``state=absent`` (https://github.com/ansible-collections/community.general/pull/4945). diff --git a/plugins/modules/cloud/misc/proxmox.py b/plugins/modules/cloud/misc/proxmox.py index da8783e16d..dccfdc7b67 100644 --- a/plugins/modules/cloud/misc/proxmox.py +++ b/plugins/modules/cloud/misc/proxmox.py @@ -743,6 +743,8 @@ def main(): module.fail_json(msg="restarting of VM %s failed with exception: %s" % (vmid, e)) elif state == 'absent': + if not vmid: + module.exit_json(changed=False, msg='VM with hostname = %s is already absent' % hostname) try: vm = proxmox.get_vm(vmid, ignore_missing=True) if not vm: diff --git a/plugins/modules/cloud/misc/proxmox_kvm.py b/plugins/modules/cloud/misc/proxmox_kvm.py index abc63f24c3..2b38e89964 100644 --- a/plugins/modules/cloud/misc/proxmox_kvm.py +++ b/plugins/modules/cloud/misc/proxmox_kvm.py @@ -1370,6 +1370,8 @@ def main(): elif state == 'absent': status = {} + if not vmid: + module.exit_json(changed=False, msg='VM with name = %s is already absent' % name) try: vm = proxmox.get_vm(vmid, ignore_missing=True) if not vm: