2020-06-09 20:37:17 +08:00
|
|
|
---
|
2020-07-04 17:02:48 +08:00
|
|
|
- name: Lookup node IP in kubernetes
|
2022-01-05 18:26:32 +08:00
|
|
|
command: >
|
|
|
|
{{ kubectl }} get nodes {{ node }}
|
2024-09-05 11:31:46 +08:00
|
|
|
-o jsonpath-as-json='{.status.addresses[?(@.type=="InternalIP")].address}'
|
|
|
|
register: k8s_node_ips
|
2024-09-05 11:53:28 +08:00
|
|
|
changed_when: false
|
2020-07-04 17:02:48 +08:00
|
|
|
when:
|
2024-09-05 11:53:28 +08:00
|
|
|
- groups['kube_control_plane'] | length > 0
|
|
|
|
- ip is not defined
|
|
|
|
- access_ip is not defined
|
|
|
|
delegate_to: "{{ groups['kube_control_plane'] | first }}"
|
2020-06-09 20:37:17 +08:00
|
|
|
|
2020-07-28 16:39:08 +08:00
|
|
|
- name: Remove etcd member from cluster
|
2020-06-09 20:37:17 +08:00
|
|
|
environment:
|
2023-06-26 18:15:45 +08:00
|
|
|
ETCDCTL_API: "3"
|
2023-07-05 11:36:54 +08:00
|
|
|
ETCDCTL_CERT: "{{ kube_cert_dir + '/etcd/server.crt' if etcd_deployment_type == 'kubeadm' else etcd_cert_dir + '/admin-' + groups['etcd'] | first + '.pem' }}"
|
|
|
|
ETCDCTL_KEY: "{{ kube_cert_dir + '/etcd/server.key' if etcd_deployment_type == 'kubeadm' else etcd_cert_dir + '/admin-' + groups['etcd'] | first + '-key.pem' }}"
|
2022-02-23 22:46:18 +08:00
|
|
|
ETCDCTL_CACERT: "{{ kube_cert_dir + '/etcd/ca.crt' if etcd_deployment_type == 'kubeadm' else etcd_cert_dir + '/ca.pem' }}"
|
2022-02-18 23:20:23 +08:00
|
|
|
ETCDCTL_ENDPOINTS: "https://127.0.0.1:2379"
|
2023-07-05 11:36:54 +08:00
|
|
|
delegate_to: "{{ groups['etcd'] | first }}"
|
2024-09-05 11:31:46 +08:00
|
|
|
block:
|
|
|
|
- name: Lookup members infos
|
|
|
|
command: "{{ bin_dir }}/etcdctl member list"
|
|
|
|
register: etcd_members
|
|
|
|
changed_when: false
|
|
|
|
check_mode: false
|
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
- name: Remove member from cluster
|
|
|
|
vars:
|
|
|
|
node_ip: "{{ ip if ip is defined else (access_ip if access_ip is defined else (k8s_node_ips.stdout | from_json)[0]) }}"
|
|
|
|
command:
|
|
|
|
argv:
|
|
|
|
- "{{ bin_dir }}/etcdctl"
|
|
|
|
- member
|
|
|
|
- remove
|
|
|
|
- "{{ ((etcd_members.stdout_lines | select('contains', '//' + node_ip + ':'))[0] | split(','))[0] }}"
|
2024-09-05 11:53:28 +08:00
|
|
|
register: etcd_removal_output
|
|
|
|
changed_when: "'Removed member' in etcd_removal_output.stdout"
|