diff --git a/example/config.yml b/example/config.yml index e498af2..d013ecc 100644 --- a/example/config.yml +++ b/example/config.yml @@ -26,6 +26,13 @@ CONTEXT_NAME: "context-{{ CLUSTER_NAME }}" # k8s version K8S_VER: "__k8s_ver__" +# set unique 'k8s_nodename' for each node, if not set(default:'') ip add will be used +K8S_NODENAME: "{%- if k8s_nodename != '' -%} \ + {{ k8s_nodename }} \ + {%- else -%} \ + {{ inventory_hostname }} \ + {%- endif -%}" + ############################ # role:etcd ############################ diff --git a/example/hosts.allinone b/example/hosts.allinone index 042cf4c..9713b9c 100644 --- a/example/hosts.allinone +++ b/example/hosts.allinone @@ -64,9 +64,5 @@ cluster_dir="{{ base_dir }}/clusters/_cluster_name_" # CA and other components cert/key Directory ca_dir="/etc/kubernetes/ssl" -# set unique 'k8s_nodename' for each node, if not set(default:'') ip add will be used -K8S_NODENAME: "{%- if k8s_nodename != '' -%} \ - {{ k8s_nodename }} \ - {%- else -%} \ - {{ inventory_hostname }} \ - {%- endif -%}" +# Default 'k8s_nodename' is empty +k8s_nodename='' diff --git a/example/hosts.multi-node b/example/hosts.multi-node index b8bc964..ad13263 100644 --- a/example/hosts.multi-node +++ b/example/hosts.multi-node @@ -68,9 +68,5 @@ cluster_dir="{{ base_dir }}/clusters/_cluster_name_" # CA and other components cert/key Directory ca_dir="/etc/kubernetes/ssl" -# set unique 'k8s_nodename' for each node, if not set(default:'') ip add will be used -K8S_NODENAME: "{%- if k8s_nodename != '' -%} \ - {{ k8s_nodename }} \ - {%- else -%} \ - {{ inventory_hostname }} \ - {%- endif -%}" +# Default 'k8s_nodename' is empty +k8s_nodename='' diff --git a/playbooks/32.delnode.yml b/playbooks/32.delnode.yml index fe0701c..e8d5309 100644 --- a/playbooks/32.delnode.yml +++ b/playbooks/32.delnode.yml @@ -20,8 +20,14 @@ - name: debug info debug: var="DRAIN_OPT" - - name: run kubectl drain @{{ NODE_TO_DEL }} - shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_TO_DEL }} {{ DRAIN_OPT }}" + - name: get the node name to delete + shell: "{{ base_dir }}/bin/kubectl get node -owide|grep ' {{ NODE_TO_DEL }} '|awk '{print $1}'" + register: NODE_NAME + + - debug: var="NODE_NAME.stdout" + + - name: run kubectl drain @{{ NODE_NAME.stdout }} + shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_NAME.stdout }} {{ DRAIN_OPT }}" #ignore_errors: true - name: clean node {{ NODE_TO_DEL }} @@ -35,8 +41,8 @@ - debug: var="CLEAN_STATUS" - - name: run kubectl delete node {{ NODE_TO_DEL }} - shell: "{{ base_dir }}/bin/kubectl delete node {{ NODE_TO_DEL }}" + - name: run kubectl delete node {{ NODE_NAME.stdout }} + shell: "{{ base_dir }}/bin/kubectl delete node {{ NODE_NAME.stdout }}" ignore_errors: true # lineinfile is inadequate to delete lines between some specific line range diff --git a/playbooks/33.delmaster.yml b/playbooks/33.delmaster.yml index 9016288..7c57b97 100644 --- a/playbooks/33.delmaster.yml +++ b/playbooks/33.delmaster.yml @@ -20,8 +20,14 @@ - name: debug info debug: var="DRAIN_OPT" - - name: run kubectl drain @{{ NODE_TO_DEL }} - shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_TO_DEL }} {{ DRAIN_OPT }}" + - name: get the node name to delete + shell: "{{ base_dir }}/bin/kubectl get node -owide|grep ' {{ NODE_TO_DEL }} '|awk '{print $1}'" + register: NODE_NAME + + - debug: var="NODE_NAME.stdout" + + - name: run kubectl drain @{{ NODE_NAME.stdout }} + shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_NAME.stdout }} {{ DRAIN_OPT }}" #ignore_errors: true - name: clean node {{ NODE_TO_DEL }} @@ -36,8 +42,8 @@ - debug: var="CLEAN_STATUS" - - name: run kubectl delete node {{ NODE_TO_DEL }} - shell: "{{ base_dir }}/bin/kubectl delete node {{ NODE_TO_DEL }}" + - name: run kubectl delete node {{ NODE_NAME.stdout }} + shell: "{{ base_dir }}/bin/kubectl delete node {{ NODE_NAME.stdout }}" ignore_errors: true # lineinfile is inadequate to delete lines between some specific line range