From cfd4879d63dd04df638219f28cced0b3befc0a15 Mon Sep 17 00:00:00 2001 From: Nikita Volodin Date: Sat, 15 Jun 2024 20:15:17 -0400 Subject: [PATCH] Install killall,uninstall scripts into k3s_install_dir Closes #223 --- tasks/ensure_installed_node.yml | 4 ++-- tasks/ensure_uninstalled.yml | 10 +++++----- tasks/post_checks_uninstalled.yml | 4 ++-- templates/k3s-uninstall.sh.j2 | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tasks/ensure_installed_node.yml b/tasks/ensure_installed_node.yml index e2a7b0f..070ff82 100644 --- a/tasks/ensure_installed_node.yml +++ b/tasks/ensure_installed_node.yml @@ -85,7 +85,7 @@ - name: Ensure k3s killall script is present ansible.builtin.template: src: k3s-killall.sh.j2 - dest: "/usr/local/bin/k3s-killall.sh" + dest: "{{ k3s_install_dir }}/k3s-killall.sh" mode: 0700 become: "{{ k3s_become }}" when: @@ -95,7 +95,7 @@ - name: Ensure k3s uninstall script is present ansible.builtin.template: src: k3s-uninstall.sh.j2 - dest: "/usr/local/bin/k3s-uninstall.sh" + dest: "{{ k3s_install_dir }}/k3s-uninstall.sh" mode: 0700 become: "{{ k3s_become }}" when: diff --git a/tasks/ensure_uninstalled.yml b/tasks/ensure_uninstalled.yml index b944afd..a7652f2 100644 --- a/tasks/ensure_uninstalled.yml +++ b/tasks/ensure_uninstalled.yml @@ -2,17 +2,17 @@ - name: Check to see if k3s-killall.sh exits ansible.builtin.stat: - path: /usr/local/bin/k3s-killall.sh + path: "{{ k3s_install_dir }}/k3s-killall.sh" register: check_k3s_killall_script - name: Check to see if k3s-uninstall.sh exits ansible.builtin.stat: - path: /usr/local/bin/k3s-uninstall.sh + path: "{{ k3s_install_dir }}/k3s-uninstall.sh" register: check_k3s_uninstall_script - name: Run k3s-killall.sh ansible.builtin.command: - cmd: /usr/local/bin/k3s-killall.sh + cmd: "{{ k3s_install_dir }}/k3s-killall.sh" register: k3s_killall changed_when: k3s_killall.rc == 0 when: check_k3s_killall_script.stat.exists @@ -20,9 +20,9 @@ - name: Run k3s-uninstall.sh ansible.builtin.command: - cmd: /usr/local/bin/k3s-uninstall.sh + cmd: "{{ k3s_install_dir }}/k3s-uninstall.sh" args: - removes: /usr/local/bin/k3s-uninstall.sh + removes: "{{ k3s_install_dir }}/k3s-uninstall.sh" register: k3s_uninstall changed_when: k3s_uninstall.rc == 0 when: check_k3s_uninstall_script.stat.exists diff --git a/tasks/post_checks_uninstalled.yml b/tasks/post_checks_uninstalled.yml index 8b125fb..c2ddc6c 100644 --- a/tasks/post_checks_uninstalled.yml +++ b/tasks/post_checks_uninstalled.yml @@ -22,7 +22,7 @@ - name: Check k3s-killall.sh is removed ansible.builtin.stat: - path: /usr/local/bin/k3s-killall.sh + path: "{{ k3s_install_dir }}/k3s-killall.sh" register: check_k3s_killall - name: Fail if k3s-killall.sh script still exists @@ -32,7 +32,7 @@ - name: Check k3s-uninstall.sh is removed ansible.builtin.stat: - path: /usr/local/bin/k3s-uninstall.sh + path: "{{ k3s_install_dir }}/k3s-uninstall.sh" register: check_k3s_uninstall - name: Fail if k3s-uninstall.sh script still exists diff --git a/templates/k3s-uninstall.sh.j2 b/templates/k3s-uninstall.sh.j2 index 0320f38..ee71384 100644 --- a/templates/k3s-uninstall.sh.j2 +++ b/templates/k3s-uninstall.sh.j2 @@ -2,7 +2,7 @@ set -x [ $(id -u) -eq 0 ] || exec sudo $0 $@ -/usr/local/bin/k3s-killall.sh +{{ k3s_install_dir }}/k3s-killall.sh if command -v systemctl; then systemctl disable k3s @@ -17,7 +17,7 @@ rm -f {{ k3s_systemd_unit_dir }}/k3s.service rm -f {{ k3s_systemd_unit_dir }}/k3s.env remove_uninstall() { - rm -f /usr/local/bin/k3s-uninstall.sh + rm -f {{ k3s_install_dir }}/k3s-uninstall.sh } trap remove_uninstall EXIT @@ -38,7 +38,7 @@ rm -rf /run/flannel rm -rf {{ k3s_runtime_config['data-dir'] | default(k3s_data_dir) }} rm -rf /var/lib/kubelet rm -f {{ k3s_install_dir }}/k3s -rm -f /usr/local/bin/k3s-killall.sh +rm -f {{ k3s_install_dir }}/k3s-killall.sh if type yum >/dev/null 2>&1; then yum remove -y k3s-selinux