Unverified Commit f369e3a0 authored by Derek Nola's avatar Derek Nola Committed by GitHub
Browse files

Simplify reset playbook (#230)



* Simplify reset playbook

Signed-off-by: default avatarDerek Nola <derek.nola@suse.com>

* Cleanup ansible_user kubeconfig

Signed-off-by: default avatarDerek Nola <derek.nola@suse.com>

---------

Signed-off-by: default avatarDerek Nola <derek.nola@suse.com>
parent dfc23c81
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -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

roles/reset/tasks/main.yml

deleted100644 → 0
+0 −50
Original line number Diff line number Diff line
---
- 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
+0 −16
Original line number Diff line number Diff line
---
- 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 }}"