blob: be55d11e90b3d11a76c266e172bae0e7a84b61df (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
---
- name: check for nodes to be removed
hosts: _kubernetes_primary_master_
tasks:
- name: fetch list of current nodes
command: kubectl get nodes -o name
changed_when: False
check_mode: no
register: kubectl_node_list
- name: generate list of nodes to be removed
loop: "{{ kubectl_node_list.stdout_lines | map('replace', 'node/', '') | list | difference(groups['_kubernetes_nodes_']) }}"
add_host:
name: "{{ item }}"
inventory_dir: "{{ hostvars[item].inventory_dir }}"
group: _kubernetes_nodes_remove_
changed_when: False
- name: drain superflous nodes
loop: "{{ groups['_kubernetes_nodes_remove_'] | default([]) }}"
command: "kubectl drain {{ item }} --delete-local-data --force --ignore-daemonsets"
- name: try to clean superflous nodes
hosts: _kubernetes_nodes_remove_
roles:
- role: kubernetes/kubeadm/reset
- role: kubernetes/net/kubeguard
when: hostvars[groups['_kubernetes_primary_master_'][0]].kubernetes_network_plugin == 'kubeguard'
vars:
kubeguard_action: remove
- name: remove node from api server
hosts: _kubernetes_primary_master_
tasks:
- name: remove superflous nodes
loop: "{{ groups['_kubernetes_nodes_remove_'] | default([]) }}"
command: "kubectl delete node {{ item }}"
|