---
- name: Unregister VMs
  gather_facts: true
  hosts:
    - masters
    - infras
    - nodes
    - lb
  roles:
    - rhsm-unregister
  ignore_errors: yes

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

  vars_files:
    - vars/ovirt-39-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 }}"
    - name: Clean DNS
      command: "nsupdate -k ../rndc.key -v nsupdate-clean.txt"
      ignore_errors: yes

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