fix(cleanup): wait for the guest shutdown before forcing the VM off

This commit is contained in:
2026-07-15 00:05:38 +02:00
parent 975384661e
commit 723f0516da
3 changed files with 47 additions and 8 deletions

View File

@@ -6,7 +6,34 @@
module_defaults:
community.proxmox.proxmox_disk: "{{ _proxmox_auth }}"
community.proxmox.proxmox_kvm: "{{ _proxmox_auth_node }}"
community.proxmox.proxmox_vm_info: "{{ _proxmox_auth_node }}"
block:
# shutdown.yml halts the guest without waiting for it, so stopping a VM Proxmox has
# already stopped errors out. Wait the shutdown out, and force off only a guest that
# ignored it. The disks come off afterwards, so they are never detached from a
# running VM.
- name: Wait for the installer environment to power off
community.proxmox.proxmox_vm_info:
vmid: "{{ system_cfg.id }}"
register: cleanup_proxmox_power
until: >-
((cleanup_proxmox_power.proxmox_vms | default([]) | first | default({})).status
| default('')) == 'stopped'
retries: "{{ cleanup_poweroff_retries }}"
delay: "{{ cleanup_poweroff_delay }}"
failed_when: false
no_log: true
- name: Force the installer environment off when it did not shut down
when: >-
((cleanup_proxmox_power.proxmox_vms | default([]) | first | default({})).status
| default('')) != 'stopped'
community.proxmox.proxmox_kvm:
vmid: "{{ system_cfg.id }}"
state: stopped
force: true
no_log: true
- name: Cleanup Setup Disks
community.proxmox.proxmox_disk:
name: "{{ hostname }}"
@@ -21,13 +48,6 @@
failed_when: false
no_log: true
- name: Ensure the installer environment is powered off
community.proxmox.proxmox_kvm:
vmid: "{{ system_cfg.id }}"
state: stopped
force: true
no_log: true
- name: Boot the installed OS
community.proxmox.proxmox_kvm:
vmid: "{{ system_cfg.id }}"