mirror of
https://github.com/PyratLabs/ansible-role-k3s
synced 2024-11-06 22:03:29 +01:00
39 lines
1.3 KiB
YAML
39 lines
1.3 KiB
YAML
|
---
|
||
|
|
||
|
- name: Check if kubectl exists
|
||
|
stat:
|
||
|
path: "{{ k3s_install_dir }}/kubectl"
|
||
|
register: k3s_check_kubectl
|
||
|
|
||
|
- name: Clean up nodes that are in an uninstalled state
|
||
|
block:
|
||
|
|
||
|
- name: Gather a list of nodes
|
||
|
command: "{{ k3s_install_dir }}/kubectl get nodes"
|
||
|
changed_when: false
|
||
|
failed_when: false
|
||
|
delegate_to: "{{ k3s_control_delegate }}"
|
||
|
run_once: true
|
||
|
register: kubectl_get_nodes_result
|
||
|
|
||
|
- name: Ensure uninstalled nodes are drained
|
||
|
command: "{{ k3s_install_dir }}/kubectl drain {{ item }} --ignore-daemonsets"
|
||
|
delegate_to: "{{ k3s_control_delegate }}"
|
||
|
run_once: true
|
||
|
when: item in kubectl_get_nodes_result.stdout
|
||
|
and hostvars[item].k3s_cluster_state is defined
|
||
|
and hostvars[item].k3s_cluster_state == 'uninstalled'
|
||
|
loop: "{{ play_hosts }}"
|
||
|
|
||
|
- name: Ensure uninstalled nodes are removed
|
||
|
command: "{{ k3s_install_dir }}/kubectl delete node {{ item }}"
|
||
|
delegate_to: "{{ k3s_control_delegate }}"
|
||
|
run_once: true
|
||
|
when: item in kubectl_get_nodes_result.stdout
|
||
|
and hostvars[item].k3s_cluster_state is defined
|
||
|
and hostvars[item].k3s_cluster_state == 'uninstalled'
|
||
|
loop: "{{ play_hosts }}"
|
||
|
|
||
|
when: k3s_check_kubectl.stat.exists is defined
|
||
|
and k3s_check_kubectl.stat.exists
|