diff --git a/playbook/reset.yml b/playbook/reset.yml index a8cc8a22..2a1ab805 100644 --- a/playbook/reset.yml +++ b/playbook/reset.yml @@ -3,5 +3,12 @@ hosts: k3s_cluster gather_facts: true become: true - roles: - - role: reset + tasks: + - name: Run K3s Uninstall script + ansible.builtin.command: + cmd: k3s-uninstall.sh + removes: /var/lib/rancher/k3s/* + - name: Remove user kubeconfig + ansible.builtin.file: + path: /home/{{ ansible_user }}/.kube/config + state: absent diff --git a/roles/reset/tasks/main.yml b/roles/reset/tasks/main.yml deleted file mode 100644 index 40bfbf13..00000000 --- a/roles/reset/tasks/main.yml +++ /dev/null @@ -1,50 +0,0 @@ ---- -- name: Clean previous failed runs of k3s-init - # systemd builtin does not support reset-failed - ansible.builtin.command: systemctl reset-failed k3s-init # noqa: command-instead-of-module - failed_when: false - changed_when: false - -- name: Disable services - ansible.builtin.systemd: - name: "{{ item }}" - state: stopped - enabled: false - failed_when: false - with_items: - - k3s-init - - k3s-server - - k3s-agent - -- name: Kill container shim - ansible.builtin.command: pkill -9 -f "k3s/data/[^/]+/bin/containerd-shim-runc" - register: pkill_containerd_shim_runc - changed_when: "pkill_containerd_shim_runc.rc == 0" - failed_when: false - -- name: Umount k3s filesystems - ansible.builtin.include_tasks: umount_with_children.yml - with_items: - - /run/k3s - - /var/lib/kubelet - - /run/netns - - "{{ k3s_server_location }}" - loop_control: - loop_var: mounted_fs - -- name: Remove service files, binaries, and data - ansible.builtin.file: - name: "{{ item }}" - state: absent - with_items: - - /usr/local/bin/k3s - - "{{ systemd_dir }}/k3s-server.service" - - "{{ systemd_dir }}/k3s-agent.service" - - /etc/rancher/k3s - - /var/lib/kubelet - - /var/lib/rancher/k3s - - "{{ k3s_server_location }}" - -- name: Systemd daemon reload - ansible.builtin.systemd: - daemon_reload: true diff --git a/roles/reset/tasks/umount_with_children.yml b/roles/reset/tasks/umount_with_children.yml deleted file mode 100644 index 130281c3..00000000 --- a/roles/reset/tasks/umount_with_children.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- name: Get the list of mounted filesystems - ansible.builtin.shell: set -o pipefail && cat /proc/mounts | awk '{ print $2}' | grep -E "^{{ mounted_fs }}" - register: get_mounted_filesystems - args: - executable: /bin/bash - failed_when: false - changed_when: get_mounted_filesystems.stdout | length > 0 - check_mode: false - -- name: Umount filesystem - ansible.posix.mount: - path: "{{ item }}" - state: unmounted - with_items: - "{{ get_mounted_filesystems.stdout_lines | reverse | list }}"