---
- hosts: localhost
  ignore_errors: yes
  vars_files:
    - vars/main.yaml
  roles:
    - instance-groups

- hosts: allnodes
  ignore_errors: yes
  vars_files:
    - vars/main.yaml
  roles:
    - rhsm-unregister

- hosts: localhost
  user: root
  become: false
  ignore_errors: yes
  vars_files:
    - vars/main.yaml
  tasks:
    - name: Delete all added VMs
      vmware_guest:
        hostname: "{{ vcenter_host }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: False
        name: "{{ hostvars[item].inventory_hostname }}"
        datacenter: "{{ vcenter_datacenter }}"
        folder: "/{{ vcenter_folder }}"
        state: absent
        force: true
      with_items: "{{ groups['allnodes'] }}"

- hosts: localhost
  user: root
  become: false
  ignore_errors: yes
  vars_files:
    - vars/main.yaml
  tasks:
    - name: "Remove resource pool on vCenter"
      vmware_resource_pool:
        hostname: "{{ vcenter_host }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: False
        datacenter: "{{ vcenter_datacenter }}"
        cluster: "{{ vcenter_cluster}}"
        resource_pool: "{{ vcenter_resource_pool }}"
        state: "absent"
    - name: "Remove folder on vCenter"
      vmware_folder:
        hostname: "{{ vcenter_host }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        validate_certs: False
        datacenter: "{{ vcenter_datacenter }}"
        cluster: "{{ vcenter_cluster}}"
        folder: "{{ vcenter_folder }}"
        state: "absent"
