2018-03-05 07:02:47 +00:00
|
|
|
---
|
2019-08-07 11:46:50 +00:00
|
|
|
- name: Lookup node IP in kubernetes
|
|
|
|
shell: >-
|
|
|
|
{{ bin_dir }}/kubectl get nodes {{ node }}
|
|
|
|
-o jsonpath='{range.status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}'
|
|
|
|
register: remove_node_ip
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- ip is not defined
|
|
|
|
- access_ip is not defined
|
|
|
|
delegate_to: "{{ groups['etcd']|first }}"
|
|
|
|
failed_when: false
|
|
|
|
|
|
|
|
- name: Set node IP
|
|
|
|
set_fact:
|
|
|
|
node_ip: "{{ ip | default(access_ip | default(remove_node_ip.stdout)) | trim }}"
|
2019-10-10 12:17:43 +00:00
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
2018-03-05 07:02:47 +00:00
|
|
|
|
|
|
|
- name: Delete node
|
2019-08-07 11:46:50 +00:00
|
|
|
command: "{{ bin_dir }}/kubectl delete node {{ inventory_hostname }}"
|
2018-06-23 06:40:59 +00:00
|
|
|
delegate_to: "{{ groups['kube-master']|first }}"
|
2018-03-05 07:02:47 +00:00
|
|
|
ignore_errors: yes
|
2019-08-07 11:46:50 +00:00
|
|
|
|
|
|
|
- name: Lookup etcd member id
|
|
|
|
shell: "{{ bin_dir }}/etcdctl --no-sync --endpoints={{ etcd_access_addresses }} member list | grep {{ node_ip }} | cut -d: -f1"
|
|
|
|
register: etcd_member_id
|
|
|
|
ignore_errors: true
|
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
environment:
|
|
|
|
ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}.pem"
|
|
|
|
ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}-key.pem"
|
|
|
|
ETCDCTL_CA_FILE: "{{ etcd_cert_dir }}/ca.pem"
|
|
|
|
delegate_to: "{{ groups['etcd']|first }}"
|
|
|
|
when: inventory_hostname in groups['etcd']
|
|
|
|
|
|
|
|
- name: Remove etcd member from cluster
|
|
|
|
shell: "{{ bin_dir }}/etcdctl --no-sync --endpoints={{ etcd_access_addresses }} member remove {{ etcd_member_id.stdout }}"
|
|
|
|
register: etcd_member_in_cluster
|
|
|
|
ignore_errors: true
|
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
environment:
|
|
|
|
ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}.pem"
|
|
|
|
ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}-key.pem"
|
|
|
|
ETCDCTL_CA_FILE: "{{ etcd_cert_dir }}/ca.pem"
|
|
|
|
delegate_to: "{{ groups['etcd']|first }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
2019-08-07 15:26:51 +00:00
|
|
|
- etcd_member_id.stdout | length > 0
|