---
- name: Unregister VMs
  hosts:
    - tag_openshift_master
    - tag_openshift_infra
    - tag_openshift_node
    - tag_openshift_lb
  roles:
    - rhsm-unregister

- name: oVirt infra destroy
  hosts: localhost
  connection: local
  gather_facts: false

  vars_files:
    - vars/ovirt-infra-vars.yaml

  pre_tasks:
    - name: Log in to oVirt
      ovirt_auth:
        url: "{{ engine_url }}"
        username: "{{ engine_user }}"
        password: "{{ engine_password }}"
        ca_file: "{{ engine_cafile | default(omit) }}"
        insecure: "{{ engine_insecure | default(true) }}"
      tags:
        - always

  tasks:
    - name: Erase vms
      ovirt_vms:
        auth: "{{ ovirt_auth }}"
        state: absent
        name: "{{ item.name }}"
      with_items:
        - "{{ vms }}"

  post_tasks:
    - name: Logout from oVirt
      ovirt_auth:
        state: absent
        ovirt_auth: "{{ ovirt_auth }}"
      tags:
        - always
