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

@@ -5,13 +5,28 @@
become: false
module_defaults:
community.vmware.vmware_guest: "{{ _vmware_auth }}"
community.vmware.vmware_guest_info: "{{ _vmware_auth }}"
vmware.vmware.vm_powerstate: "{{ _vmware_auth }}"
no_log: true
block:
- name: Ensure the installer environment is powered off
# shutdown.yml halts the guest without waiting for it, so powering off a VM that
# vCenter has already stopped raises InvalidPowerState. Wait the shutdown out, and
# force off only a guest that ignored it.
- name: Wait for the installer environment to power off
community.vmware.vmware_guest_info:
name: "{{ hostname }}"
register: cleanup_vmware_power
until: (cleanup_vmware_power.instance.hw_power_status | default('') | lower) == 'poweredoff'
retries: "{{ cleanup_poweroff_retries }}"
delay: "{{ cleanup_poweroff_delay }}"
failed_when: false
- name: Force the installer environment off when it did not shut down
when: (cleanup_vmware_power.instance.hw_power_status | default('') | lower) != 'poweredoff'
vmware.vmware.vm_powerstate:
name: "{{ hostname }}"
state: powered-off
force: true
- name: Remove CD-ROM from VM in vCenter
community.vmware.vmware_guest: