2019-07-24 10:19:31 +08:00
|
|
|
# WARNNING: this playbook will clean the node {{ NODE_TO_DEL }}
|
|
|
|
# USAGE: easzctl del-node 1.1.1.1
|
2019-06-03 11:25:05 +08:00
|
|
|
|
2019-07-24 10:19:31 +08:00
|
|
|
- hosts: localhost
|
2019-06-03 11:25:05 +08:00
|
|
|
tasks:
|
2019-07-24 10:19:31 +08:00
|
|
|
- fail: msg="you CAN NOT delete the last member of kube-master!"
|
2019-06-03 11:25:05 +08:00
|
|
|
when: "groups['kube-master']|length < 2 and NODE_TO_DEL in groups['kube-master']"
|
|
|
|
|
2019-07-24 10:19:31 +08:00
|
|
|
- name: run kubectl drain @{{ NODE_TO_DEL }}
|
2019-06-03 11:25:05 +08:00
|
|
|
shell: "{{ bin_dir }}/kubectl drain {{ NODE_TO_DEL }} --ignore-daemonsets --delete-local-data"
|
|
|
|
ignore_errors: true
|
|
|
|
|
2019-07-24 10:19:31 +08:00
|
|
|
- name: clean node {{ NODE_TO_DEL }} if possible
|
|
|
|
shell: "ansible-playbook {{ base_dir }}/roles/clean/clean_node.yml \
|
|
|
|
-e NODE_TO_CLEAN={{ NODE_TO_DEL }} \
|
|
|
|
-e DEL_NODE=yes \
|
2019-07-24 23:18:52 +08:00
|
|
|
-e DEL_LB=yes >> /tmp/ansible-`date +'%Y%m%d%H%M%S'`.log 2>&1 \
|
2019-07-24 10:19:31 +08:00
|
|
|
|| echo 'data not cleaned on {{ NODE_TO_DEL }}'"
|
|
|
|
register: CLEAN_STATUS
|
|
|
|
|
|
|
|
- debug: var="CLEAN_STATUS.stdout"
|
2019-06-03 11:25:05 +08:00
|
|
|
|
2019-11-26 11:06:12 +08:00
|
|
|
- debug: var="CLEAN_STATUS.stderr"
|
|
|
|
|
2019-07-24 10:19:31 +08:00
|
|
|
- name: run kubectl delete node {{ NODE_TO_DEL }}
|
|
|
|
shell: "{{ bin_dir }}/kubectl delete node {{ NODE_TO_DEL }}"
|
|
|
|
ignore_errors: true
|
2019-07-24 23:18:52 +08:00
|
|
|
|
|
|
|
# lineinfile is inadequate to delete lines between some specific line range
|
|
|
|
- name: remove the node's entry in hosts
|
|
|
|
shell: 'sed -i "/^\[kube-node/,/^\[harbor/ {/^{{ NODE_TO_DEL }}[^0-9]*$/d}" {{ base_dir }}/hosts'
|
|
|
|
args:
|
|
|
|
warn: false
|