2020-05-18 20:53:03 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
- name: Check if kubectl exists
|
|
|
|
stat:
|
|
|
|
path: "{{ k3s_install_dir }}/kubectl"
|
|
|
|
register: k3s_check_kubectl
|
2020-05-20 19:50:58 +02:00
|
|
|
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"
|
2020-05-18 20:53:03 +02:00
|
|
|
|
|
|
|
- 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
|
2020-05-20 19:50:58 +02:00
|
|
|
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"
|
2020-05-18 20:53:03 +02:00
|
|
|
|
|
|
|
- name: Ensure uninstalled nodes are drained
|
2020-10-23 14:43:58 +02:00
|
|
|
command: "{{ k3s_install_dir }}/kubectl drain {{ item }} --ignore-daemonsets --delete-local-data"
|
2020-05-18 20:53:03 +02:00
|
|
|
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 }}"
|
2020-05-20 19:50:58 +02:00
|
|
|
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"
|
2020-05-18 20:53:03 +02:00
|
|
|
|
|
|
|
- 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 }}"
|
2020-05-20 19:50:58 +02:00
|
|
|
become: "{{ k3s_become_for_kubectl | ternary(true, false, k3s_become_for_all) }}"
|
2020-05-18 20:53:03 +02:00
|
|
|
|
|
|
|
when: k3s_check_kubectl.stat.exists is defined
|
|
|
|
and k3s_check_kubectl.stat.exists
|
2020-05-25 17:25:09 +02:00
|
|
|
and k3s_control_delegate is defined
|
2020-07-25 18:39:01 +02:00
|
|
|
and not ansible_check_mode
|