From c57204f9a944ec8ef821fcf413c3a76ef255e485 Mon Sep 17 00:00:00 2001 From: miyuk Date: Thu, 21 Jul 2022 14:19:44 +0900 Subject: [PATCH] proxmox module_utils: fix get_vm int parse handling (#4945) * add int parse handling * Revert "add int parse handling" This reverts commit db2aac42540a9af69fe58ac055c2e5b97923701b. * fix: vmid check if state is absent * add changelogs fragments * Update changelogs/fragments/4945-fix-get_vm-int-parse-handling.yaml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- changelogs/fragments/4945-fix-get_vm-int-parse-handling.yaml | 3 +++ plugins/modules/cloud/misc/proxmox.py | 2 ++ plugins/modules/cloud/misc/proxmox_kvm.py | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 changelogs/fragments/4945-fix-get_vm-int-parse-handling.yaml 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: