From 7d68af57af0e43509f08c8243b4acc4c1d09b8f3 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sun, 23 Jul 2023 22:53:02 +0200 Subject: [PATCH] [PR #6914/17b4219b backport][stable-7] proxmox_kvm: enable 'force' restart of vm (as documented) (#6997) proxmox_kvm: enable 'force' restart of vm (as documented) (#6914) * enable 'force' restart of vm * added changelog fragment * Update changelogs/fragments/6914-proxmox_kvm-enable-force-restart.yml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein (cherry picked from commit 17b4219b8b360dac8e4dc58880a4368e4adc94d3) Co-authored-by: Jeff Turner --- .../fragments/6914-proxmox_kvm-enable-force-restart.yml | 2 ++ plugins/modules/proxmox_kvm.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/6914-proxmox_kvm-enable-force-restart.yml diff --git a/changelogs/fragments/6914-proxmox_kvm-enable-force-restart.yml b/changelogs/fragments/6914-proxmox_kvm-enable-force-restart.yml new file mode 100644 index 0000000000..4767f36f15 --- /dev/null +++ b/changelogs/fragments/6914-proxmox_kvm-enable-force-restart.yml @@ -0,0 +1,2 @@ +minor_changes: + - proxmox_kvm - enabled force restart of VM, bringing the ``force`` parameter functionality in line with what is described in the docs (https://github.com/ansible-collections/community.general/pull/6914). diff --git a/plugins/modules/proxmox_kvm.py b/plugins/modules/proxmox_kvm.py index 45b042316a..c3c51e4570 100644 --- a/plugins/modules/proxmox_kvm.py +++ b/plugins/modules/proxmox_kvm.py @@ -1111,11 +1111,11 @@ class ProxmoxKvmAnsible(ProxmoxAnsible): return False return True - def restart_vm(self, vm, **status): + def restart_vm(self, vm, force, **status): vmid = vm['vmid'] try: proxmox_node = self.proxmox_api.nodes(vm['node']) - taskid = proxmox_node.qemu(vmid).status.reboot.post() + taskid = proxmox_node.qemu(vmid).status.reset.post() if force else proxmox_node.qemu(vmid).status.reboot.post() if not self.wait_for_task(vm['node'], taskid): self.module.fail_json(msg='Reached timeout while waiting for rebooting VM. Last line in task before timeout: %s' % proxmox_node.tasks(taskid).log.get()[:1]) @@ -1493,7 +1493,7 @@ def main(): if vm['status'] == 'stopped': module.exit_json(changed=False, vmid=vmid, msg="VM %s is not running" % vmid, **status) - if proxmox.restart_vm(vm): + if proxmox.restart_vm(vm, force=module.params['force']): module.exit_json(changed=True, vmid=vmid, msg="VM %s is restarted" % vmid, **status) elif state == 'absent':