diff --git a/ezctl b/ezctl index bf1aee1..a34ab4d 100755 --- a/ezctl +++ b/ezctl @@ -294,10 +294,11 @@ function add-node() { [[ $2 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { logger error "Invalid ip add:$2"; return 1; } # check if the new node already exsited - sed -n '/^\[kube_master/,/^\[harbor/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]*$" && { logger error "node $2 already existed in $BASE/clusters/$1/hosts"; return 2; } + sed -n '/^\[kube_master/,/^\[harbor/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]" && { logger error "node $2 already existed in $BASE/clusters/$1/hosts"; return 2; } logger info "add $2 into 'kube_node' group" - sed -i "/\[kube_node/a $2 NEW_NODE=yes ${@:3}" "$BASE/clusters/$1/hosts" + NODE_INFO="${@:2}" + sed -i "/\[kube_node/a $NODE_INFO" "$BASE/clusters/$1/hosts" logger info "start to add a work node:$2 into cluster:$1" ansible-playbook -i "$BASE/clusters/$1/hosts" "$BASE/playbooks/22.addnode.yml" -e "NODE_TO_ADD=$2" -e "@clusters/$1/config.yml" @@ -308,10 +309,11 @@ function add-master() { [[ $2 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { logger error "Invalid ip add:$2"; return 1; } # check if the new master already exsited - sed -n '/^\[kube_master/,/^\[kube_node/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]*$" && { logger error "master $2 already existed!"; return 2; } + sed -n '/^\[kube_master/,/^\[kube_node/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]" && { logger error "master $2 already existed!"; return 2; } logger info "add $2 into 'kube_master' group" - sed -i "/\[kube_master/a $2 NEW_MASTER=yes ${@:3}" "$BASE/clusters/$1/hosts" + MASTER_INFO="${@:2}" + sed -i "/\[kube_master/a $MASTER_INFO" "$BASE/clusters/$1/hosts" logger info "start to add a master node:$2 into cluster:$1" ansible-playbook -i "$BASE/clusters/$1/hosts" "$BASE/playbooks/23.addmaster.yml" -e "NODE_TO_ADD=$2" -e "@clusters/$1/config.yml" @@ -325,10 +327,11 @@ function add-etcd() { [[ $2 =~ ^(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})(\.(2(5[0-5]{1}|[0-4][0-9]{1})|[0-1]?[0-9]{1,2})){3}$ ]] || { logger error "Invalid ip add:$2"; return 1; } # check if the new node already exsited - sed -n '/^\[etcd/,/^\[kube_master/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]*$" && { logger error "etcd $2 already existed!"; return 2; } + sed -n '/^\[etcd/,/^\[kube_master/p' "$BASE/clusters/$1/hosts"|grep "^$2[^0-9]" && { logger error "etcd $2 already existed!"; return 2; } logger info "add $2 into 'etcd' group" - sed -i "/\[etcd/a $2 NEW_ETCD=yes ${@:3}" "$BASE/clusters/$1/hosts" + ETCD_INFO="${@:2}" + sed -i "/\[etcd/a $ETCD_INFO" "$BASE/clusters/$1/hosts" logger info "start to add a etcd node:$2 into cluster:$1" ansible-playbook -i "$BASE/clusters/$1/hosts" "$BASE/playbooks/21.addetcd.yml" -e "NODE_TO_ADD=$2" -e "@clusters/$1/config.yml" diff --git a/playbooks/31.deletcd.yml b/playbooks/31.deletcd.yml index 04eaf25..8b02883 100644 --- a/playbooks/31.deletcd.yml +++ b/playbooks/31.deletcd.yml @@ -73,7 +73,7 @@ # lineinfile is inadequate to delete lines between some specific line range - name: remove the etcd's node entry in hosts - shell: 'sed -i "/^\[etcd/,/^\[kube_master/ {/^{{ ETCD_TO_DEL }}[^0-9]*$/d}" {{ base_dir }}/clusters/{{ CLUSTER }}/hosts' + shell: 'sed -i "/^\[etcd/,/^\[kube_master/ {/^{{ ETCD_TO_DEL }}[^0-9].*$/d}" {{ base_dir }}/clusters/{{ CLUSTER }}/hosts' args: warn: false when: "groups['etcd']|length > 1 and ETCD_TO_DEL in groups['etcd']" diff --git a/playbooks/32.delnode.yml b/playbooks/32.delnode.yml index a37ec98..caeddbd 100644 --- a/playbooks/32.delnode.yml +++ b/playbooks/32.delnode.yml @@ -26,6 +26,6 @@ # 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' + shell: 'sed -i "/^\[kube_node/,/^\[harbor/ {/^{{ NODE_TO_DEL }}[^0-9].*$/d}" {{ base_dir }}/clusters/{{ CLUSTER }}/hosts' args: warn: false diff --git a/playbooks/33.delmaster.yml b/playbooks/33.delmaster.yml index 4b01e03..8c2f8bb 100644 --- a/playbooks/33.delmaster.yml +++ b/playbooks/33.delmaster.yml @@ -27,6 +27,6 @@ # 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 }}/clusters/{{ CLUSTER }}/hosts' + shell: 'sed -i "/^\[kube_master/,/^\[harbor/ {/^{{ NODE_TO_DEL }}[^0-9].*$/d}" {{ base_dir }}/clusters/{{ CLUSTER }}/hosts' args: warn: false