# WARNNING: this playbook will clean the node {{ NODE_TO_DEL }} - hosts: localhost tasks: - fail: msg="you CAN NOT delete the last member of kube_master!" when: "groups['kube_master']|length < 2 and NODE_TO_DEL in groups['kube_master']" - name: run kubectl drain @{{ NODE_TO_DEL }} shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_TO_DEL }} --ignore-daemonsets --delete-emptydir-data --force" #ignore_errors: true - name: clean node {{ NODE_TO_DEL }} shell: "cd {{ base_dir }} && ansible-playbook -i clusters/{{ CLUSTER }}/hosts \ roles/clean/clean_node.yml \ -e NODE_TO_CLEAN={{ NODE_TO_DEL }} \ -e DEL_NODE=yes \ -e DEL_LB=yes >> /tmp/ansible-`date +'%Y%m%d%H%M%S'`.log 2>&1 \ || echo 'data not cleaned on {{ NODE_TO_DEL }}'" register: CLEAN_STATUS - debug: var="CLEAN_STATUS" - name: run kubectl delete node {{ NODE_TO_DEL }} shell: "{{ base_dir }}/bin/kubectl delete node {{ NODE_TO_DEL }}" ignore_errors: true # 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 }}/clusters/{{ CLUSTER }}/hosts' args: warn: false