---
- name: CMOA Remove (1. imxc-ui Remove)
  kubernetes.core.helm:
    name: "{{ item }}"
    release_namespace: imxc
    state: absent
    wait: true
  with_items:
    - imxc-ui
  when: kubernetes_role == 'master'

- name: CMOA Remove (2. imxc Remove)
  kubernetes.core.helm:
    name: "{{ item }}"
    release_namespace: imxc
    state: absent
    wait: true
  with_items:
    - imxc
  when: kubernetes_role == 'master'

- name: CMOA Remove (3. keycloak Remove)
  kubernetes.core.helm:
    name: "{{ item }}"
    release_namespace: imxc
    state: absent
    wait: true
  with_items:
    - keycloak
  when: kubernetes_role == 'master'

- name: CMOA Remove (4. base Remove)
  kubernetes.core.helm:
    name: "{{ item }}"
    release_namespace: imxc
    state: absent
    wait: true
  with_items:
    - base
  when: kubernetes_role == 'master'

- name: CMOA Remove (5. minio Remove)
  kubernetes.core.helm:
    name: "{{ item }}"
    release_namespace: imxc
    state: absent
    wait: true
  with_items:
    - minio
  when: kubernetes_role == 'master'

- name: CMOA Remove (6. Namespace Remove)
  kubernetes.core.k8s:
    name: imxc
    api_version: v1
    kind: namespace
    state: absent
    wait: yes
  when: kubernetes_role == 'master'

- name: CMOA Remove (7. PV Remove)
  kubernetes.core.k8s:
    name: "{{ item }}"
    api_version: v1
    kind: PersistentVolume
    state: absent
    wait: yes
  with_items:
    - minio-pv-0
    - minio-pv-1
    - minio-pv-2
    - minio-pv-3
  when: kubernetes_role == 'master'

- name: CMOA Remove (8. PV Directory Remove - 1)
  ansible.builtin.file:
    path: "{{ item }}"
    state: absent
  with_items:
    - /media/data/minio/pv1
    - /media/data/minio/pv2
    - /media/data/postgres/postgres-data-0
    - /media/data/elasticsearch/elasticsearch-data-0
    - /media/data/zookeeper/zookeeper-data-0
    - /media/data/kafka/kafka-data-0
    - /media/cloudmoa/ingester/ingester-data-1
    - /media/data/redis/redis-data-0
    - /media/data/redis/redis-data-1
    - /media/data/rabbitmq
  when: inventory_hostname in groups["worker1"]
  delegate_to: "{{ inventory_hostname }}"

- name: CMOA Remove (8. PV Directory Remove - 2)
  ansible.builtin.file:
    path: "{{ item }}"
    state: absent
  with_items:
    - /media/data/minio/pv3
    - /media/data/minio/pv4
    - /media/data/elasticsearch/elasticsearch-data-1
    - /media/data/zookeeper/zookeeper-data-1
    - /media/data/zookeeper/zookeeper-data-2
    - /media/data/kafka/kafka-data-1
    - /media/data/kafka/kafka-data-2
    - /media/cloudmoa/ingester/ingester-data-2
    - /media/cloudmoa/ingester/ingester-data-3
    - /media/data/redis/redis-data-1
    - /media/data/redis/redis-data-2
  when: inventory_hostname in groups["worker2"]
  delegate_to: "{{ inventory_hostname }}"
