From d2147b09a7011d136dd0383c92fb893d55e14d0b Mon Sep 17 00:00:00 2001 From: Marcin Stolarek Date: Fri, 15 Apr 2022 13:32:08 +0200 Subject: [PATCH] Correctly handle exception when no VM name returned by proxmox --- changelogs/fragments/4492-proxmox_kvm_fix_vm_without_name.yaml | 2 ++ plugins/modules/cloud/misc/proxmox_kvm.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/4492-proxmox_kvm_fix_vm_without_name.yaml diff --git a/changelogs/fragments/4492-proxmox_kvm_fix_vm_without_name.yaml b/changelogs/fragments/4492-proxmox_kvm_fix_vm_without_name.yaml new file mode 100644 index 00000000000..94efa9133b6 --- /dev/null +++ b/changelogs/fragments/4492-proxmox_kvm_fix_vm_without_name.yaml @@ -0,0 +1,2 @@ +bugfixes: + - proxmox_kvm - fix a bug when getting a state of VM without name will fail (https://github.com/ansible-collections/community.general/pull/4508). diff --git a/plugins/modules/cloud/misc/proxmox_kvm.py b/plugins/modules/cloud/misc/proxmox_kvm.py index 6bfb9e2e194..f80848c4c4f 100644 --- a/plugins/modules/cloud/misc/proxmox_kvm.py +++ b/plugins/modules/cloud/misc/proxmox_kvm.py @@ -1397,7 +1397,7 @@ def main(): module.fail_json(msg='VM with name = %s does not exist in cluster' % name) vm = proxmox.get_vm(vmid) if not name: - name = vm['name'] + name = vm.get('name', '(unnamed)') current = proxmox.proxmox_api.nodes(vm['node']).qemu(vmid).status.current.get()['status'] status['status'] = current if status: