Initial commit
This commit is contained in:
55
ansible/playbooks/k3s-uninstall.yml
Normal file
55
ansible/playbooks/k3s-uninstall.yml
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
- name: Uninstall k3s from cluster nodes
|
||||
hosts: k3s
|
||||
become: true
|
||||
gather_facts: true
|
||||
|
||||
pre_tasks:
|
||||
- name: Check if k3s is installed
|
||||
ansible.builtin.stat:
|
||||
path: /usr/local/bin/k3s-uninstall.sh
|
||||
register: uninstall_script
|
||||
|
||||
- name: Display uninstall status
|
||||
ansible.builtin.debug:
|
||||
msg: "k3s uninstall script found: {{ 'YES' if uninstall_script.stat.exists else 'NO' }} on {{ inventory_hostname }}"
|
||||
|
||||
tasks:
|
||||
- name: Run k3s uninstall script
|
||||
ansible.builtin.command: /usr/local/bin/k3s-uninstall.sh
|
||||
register: uninstall_result
|
||||
changed_when: uninstall_result.rc == 0
|
||||
when: uninstall_script.stat.exists
|
||||
|
||||
- name: Display uninstall result
|
||||
ansible.builtin.debug:
|
||||
msg: "k3s uninstalled successfully on {{ inventory_hostname }}"
|
||||
when:
|
||||
- uninstall_script.stat.exists
|
||||
- uninstall_result.rc == 0
|
||||
|
||||
- name: Display skip message
|
||||
ansible.builtin.debug:
|
||||
msg: "k3s was not installed on {{ inventory_hostname }} - nothing to do"
|
||||
when: not uninstall_script.stat.exists
|
||||
|
||||
- name: Clean up k3s configuration directory
|
||||
ansible.builtin.file:
|
||||
path: /etc/rancher/k3s
|
||||
state: absent
|
||||
|
||||
- name: Clean up k3s data directory
|
||||
ansible.builtin.file:
|
||||
path: /var/lib/rancher/k3s
|
||||
state: absent
|
||||
|
||||
post_tasks:
|
||||
- name: Verify k3s is removed
|
||||
ansible.builtin.command: k3s --version
|
||||
register: k3s_check
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Display verification result
|
||||
ansible.builtin.debug:
|
||||
msg: "k3s verification on {{ inventory_hostname }}: {{ 'STILL PRESENT' if k3s_check.rc == 0 else 'REMOVED' }}"
|
||||
Reference in New Issue
Block a user