improve VMware cleanup

This commit is contained in:
Sandwich 2024-10-31 01:12:51 +01:00
parent d92944c345
commit ccf3193c92
2 changed files with 48 additions and 23 deletions

View File

@ -80,7 +80,7 @@
tasks: tasks:
- name: Reboot system - name: Reboot system
when: hypervisor != "libvirt" when: hypervisor == "proxmox"
ansible.builtin.command: reboot ansible.builtin.command: reboot
failed_when: false failed_when: false
changed_when: result.rc == 0 changed_when: result.rc == 0

View File

@ -22,31 +22,56 @@
- ide0 - ide0
- ide2 - ide2
- name: Remove CD-ROM from VM in vCenter - name: Clean vCenter VM
when: hypervisor == "vmware" when: hypervisor == "vmware"
delegate_to: localhost delegate_to: localhost
become: false become: false
failed_when: false block:
community.vmware.vmware_guest: - name: Shutdown VM in vCenter
hostname: "{{ hypervisor_url }}" when: hypervisor == "vmware"
username: "{{ hypervisor_username }}" community.vmware.vmware_guest_powerstate:
password: "{{ hypervisor_password }}" hostname: "{{ hypervisor_url }}"
validate_certs: false username: "{{ hypervisor_username }}"
datacenter: "{{ hypervisor_cluster }}" password: "{{ hypervisor_password }}"
name: "{{ hostname }}" validate_certs: false
cdrom: datacenter: "{{ hypervisor_cluster }}"
- controller_number: 0 name: "{{ hostname }}"
unit_number: 0 state: powered-off
controller_type: sata
type: iso - name: Remove CD-ROM from VM in vCenter
iso_path: "{{ boot_iso }}" when: hypervisor == "vmware"
state: absent failed_when: false
- controller_number: 0 community.vmware.vmware_guest:
unit_number: 1 hostname: "{{ hypervisor_url }}"
controller_type: sata username: "{{ hypervisor_username }}"
type: iso password: "{{ hypervisor_password }}"
iso_path: "{{ rhel_iso | default(omit) }}" validate_certs: false
state: absent datacenter: "{{ hypervisor_cluster }}"
name: "{{ hostname }}"
cdrom:
- controller_number: 0
unit_number: 0
controller_type: sata
type: iso
iso_path: "{{ boot_iso }}"
state: absent
- controller_number: 0
unit_number: 1
controller_type: sata
type: iso
iso_path: "{{ rhel_iso | default(omit) }}"
state: absent
- name: Start VM in vCenter
when: hypervisor == "vmware"
community.vmware.vmware_guest_powerstate:
hostname: "{{ hypervisor_url }}"
username: "{{ hypervisor_username }}"
password: "{{ hypervisor_password }}"
validate_certs: false
datacenter: "{{ hypervisor_cluster }}"
name: "{{ hostname }}"
state: powered-on
- name: Remove Archiso and cloud-init disks - name: Remove Archiso and cloud-init disks
when: hypervisor == "libvirt" when: hypervisor == "libvirt"