---
- name: Reset Kubernetes Cluster
  command: kubeadm reset -f
  ignore_errors: yes

- name: Remove Kubernetes configuration files
  file:
    path: "{{ item }}"
    state: absent
  loop:
    - /etc/kubernetes
    - /var/lib/etcd
    - /var/lib/kubelet
    - /var/lib/dockershim
    - /var/run/kubernetes
    - /var/run/dockershim
    - /media/data
    - /media/cloudmoa

- name: container runtime stop - docker
  systemd:
    name: docker
    state: stopped
  when: runtime == "docker"

- name: container runtime stop - crio
  systemd:
    name: crio
    state: stopped
  when: runtime == "crio"

- name: container runtime stop - containerd
  systemd:
    name: containerd
    state: stopped
  when: runtime == "containerd"

- name: Remove kubectl package
  package:
    name: kubectl
    state: absent

- name: Remove kubeadm package
  package:
    name: kubeadm
    state: absent

- name: Remove kubelet package
  package:
    name: kubelet
    state: absent

- name: Remove docker
  package:
    name: docker*
    state: absent
  when: runtime == "docker"

- name: Remove containerd
  package:
    name: containerd
    state: absent
  when: runtime == "containerd"

- name: Remove crio
  package:
    name: crio
    state: absent
  when: runtime == "crio"