bugfix:删除etcd/master/node节点脚本

pull/649/head
gjmzj 2019-07-24 23:18:52 +08:00
parent effebf094b
commit 6724ebb324
4 changed files with 20 additions and 14 deletions

View File

@ -1,4 +1,4 @@
# WARNNING: this playbook will clean the etcd {{ NODE_TO_DEL }}
# WARNNING: this playbook will clean the etcd {{ ETCD_TO_DEL }}
# USAGE: easzctl del-etcd 1.1.1.1
- hosts: localhost
@ -30,6 +30,7 @@
endpoint health; \
done'
register: ETCD_CLUSTER_STATUS
ignore_errors: true
- debug: var="ETCD_CLUSTER_STATUS.stdout"
@ -55,10 +56,10 @@
delegate_to: "{{ RUNNING_NODE.stdout }}"
when: "ETCD_ID.stdout != ''"
- name: clean etcd {{ NODE_TO_DEL }} if possible
- name: clean etcd {{ ETCD_TO_DEL }} if possible
shell: "ansible-playbook {{ base_dir }}/roles/clean/clean_node.yml \
-e NODE_TO_CLEAN={{ NODE_TO_DEL }} \
-e DEL_ETCD=yes >> /tmp/ansible-playbook.log 2>&1 \
-e NODE_TO_CLEAN={{ ETCD_TO_DEL }} \
-e DEL_ETCD=yes >> /tmp/ansible-`date +'%Y%m%d%H%M%S'`.log 2>&1 \
|| echo 'data not cleaned on {{ ETCD_TO_DEL }}'"
register: CLEAN_STATUS
@ -71,5 +72,5 @@
warn: false
- name: reconfig and restart the etcd cluster
shell: "ansible-playbook {{ base_dir }}/02.etcd.yml > /tmp/ansible-playbook.log 2>&1"
shell: "ansible-playbook {{ base_dir }}/02.etcd.yml >> /tmp/ansible-`date +'%Y%m%d%H%M%S'`.log 2>&1"
when: "groups['etcd']|length > 1 and ETCD_TO_DEL in groups['etcd']"

View File

@ -14,7 +14,7 @@
shell: "ansible-playbook {{ base_dir }}/roles/clean/clean_node.yml \
-e NODE_TO_CLEAN={{ NODE_TO_DEL }} \
-e DEL_NODE=yes \
-e DEL_LB=yes >> /tmp/ansible-playbook.log 2>&1 \
-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
@ -23,3 +23,9 @@
- name: run kubectl delete node {{ NODE_TO_DEL }}
shell: "{{ bin_dir }}/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 }}/hosts'
args:
warn: false

View File

@ -15,7 +15,7 @@
-e NODE_TO_CLEAN={{ NODE_TO_DEL }} \
-e DEL_MASTER=yes \
-e DEL_NODE=yes \
-e DEL_LB=yes >> /tmp/ansible-playbook.log 2>&1 \
-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
@ -24,3 +24,9 @@
- name: run kubectl delete node {{ NODE_TO_DEL }}
shell: "{{ bin_dir }}/kubectl delete node {{ NODE_TO_DEL }}"
ignore_errors: true
# lineinfile is inadequate to delete lines between some specific line range
- name: remove the master's entry in hosts
shell: 'sed -i "/^\[kube-master/,/^\[harbor/ {/^{{ NODE_TO_DEL }}[^0-9]*$/d}" {{ base_dir }}/hosts'
args:
warn: false

View File

@ -158,9 +158,6 @@ function del-node() {
#
ansible-playbook $BASEPATH/tools/12.delnode.yml -e NODE_TO_DEL=$1 || { echo "[ERROR] Failed to delete 'kube-node': $1!"; return 2; }
# remove node in ansible hosts
sed -i '/^\[kube-node/,/^\[harbor/{/^'"$1"'[^0-9]/d}' $BASEPATH/hosts
# save current cluster context if needed
[ -f "$BASEPATH/.cluster/current_cluster" ] && save_context
return 0
@ -173,10 +170,6 @@ function del-master() {
#
ansible-playbook $BASEPATH/tools/13.delmaster.yml -e NODE_TO_DEL=$1 || { echo "[ERROR] Failed to delete 'kube-master': $1!"; return 2; }
# remove node in ansible hosts
sed -i '/^\[kube-master/,/^\[kube-node/{/^'"$1"'[^0-9]/d}' $BASEPATH/hosts
sed -i '/^\[kube-node/,/^\[harbor/{/^'"$1"'[^0-9]/d}' $BASEPATH/hosts
# reconfig kubeconfig in ansible manage node
ansible-playbook $BASEPATH/roles/deploy/deploy.yml -t create_kctl_cfg