diff --git a/tools/11.deletcd.yml b/tools/11.deletcd.yml index 709c670..9bdcd90 100644 --- a/tools/11.deletcd.yml +++ b/tools/11.deletcd.yml @@ -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']" diff --git a/tools/12.delnode.yml b/tools/12.delnode.yml index da49d23..d217ec2 100644 --- a/tools/12.delnode.yml +++ b/tools/12.delnode.yml @@ -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 diff --git a/tools/13.delmaster.yml b/tools/13.delmaster.yml index 937e58f..db2996d 100644 --- a/tools/13.delmaster.yml +++ b/tools/13.delmaster.yml @@ -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 diff --git a/tools/easzctl b/tools/easzctl index c90b525..fc7b6d4 100755 --- a/tools/easzctl +++ b/tools/easzctl @@ -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