ansible-role-k3s/templates/k3s-uninstall.sh.j2

62 lines
1.5 KiB
Django/Jinja

#!/usr/bin/env bash
set -xeuo pipefail
[[ "$(id -u)" -eq 0 ]] || exec sudo "${0}" "${@}"
remove_uninstall() {
[ -f "${0}" ] && rm -- "${0}"
exit 0
}
trap remove_uninstall EXIT
/usr/local/bin/k3s-killall.sh ; echo "k3s-killall.sh exited ${?} ..."
WSYSCTL=$(which systemctl || true)
if [[ "${WSYSCTL}" != "" ]] ; then
systemctl disable k3s
systemctl reset-failed k3s
systemctl daemon-reload
fi
WRCUPD=$(which rc-update || true)
if [[ "${WRCUPD}" != "" ]] ; then
rc-update delete k3s default
fi
K3SSVC=$(ls /etc/systemd/system/k3s*.service || true)
if [[ "${K3SSVC}" != "" ]] ; then
for unit in /etc/systemd/system/k3s*.service ; do
unit_name="$(basename "${unit}")"
systemctl stop "${unit_name}"
[ -f "${unit}" ] && rm -f "${unit}"
done
systemctl daemon-reload
fi
K3SINIT=$(ls /etc/init.d/k3s* || true)
if [[ "${K3SINIT}" != "" ]] ; then
set +x; echo 'Additional k3s services installed, skipping uninstall of k3s'; set -x
exit
fi
for cmd in {kubectl,crictl,ctr} ; do
if [ -f "{{ k3s_install_dir }}/${cmd}" ]; then
rm -f "{{ k3s_install_dir }}/${cmd}"
fi
done
for bin in {{ k3s_install_dir }}/k3s*; do
[ -f "${bin}" ] && rm -f "${bin}"
done
[ -d /etc/rancher/k3s ] && rm -rf /etc/rancher/k3s
[ -d {{ k3s_node_data_dir | default('/var/lib/rancher/k3s') }} ] && rm -rf {{ k3s_node_data_dir | default('/var/lib/rancher/k3s') }}
[ -d /var/lib/kubelet ] && rm -rf /var/lib/kubelet
[ -f /usr/local/bin/k3s-killall.sh ] && rm -f /usr/local/bin/k3s-killall.sh