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 }}
|
2022-05-03 19:56:07 +08:00
|
|
|
-o jsonpath='{range .status.addresses[?(@.type=="InternalIP")]}{@.address}{"\n"}{end}'
|
2020-07-04 17:02:48 +08:00
|
|
|
register: remove_node_ip
|
|
|
|
when:
|
2023-01-03 21:03:32 +08:00
|
|
|
- groups['kube_control_plane'] | length > 0
|
2020-07-04 17:02:48 +08:00
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- ip is not defined
|
|
|
|
- access_ip is not defined
|
|
|
|
delegate_to: "{{ groups['etcd']|first }}"
|
|
|
|
failed_when: false
|
|
|
|
|
2020-06-09 20:37:17 +08:00
|
|
|
- name: Set node IP
|
|
|
|
set_fact:
|
|
|
|
node_ip: "{{ ip | default(access_ip | default(remove_node_ip.stdout)) | trim }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
|
2020-09-01 16:05:58 +08:00
|
|
|
- name: Make sure node_ip is set
|
|
|
|
assert:
|
|
|
|
that: node_ip is defined and node_ip | length > 0
|
|
|
|
msg: "Etcd node ip is not set !"
|
2020-09-19 08:14:27 +08:00
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
2020-09-01 16:05:58 +08:00
|
|
|
|
2020-06-09 20:37:17 +08:00
|
|
|
- name: Lookup etcd member id
|
2020-07-27 14:32:29 +08:00
|
|
|
shell: "{{ bin_dir }}/etcdctl member list | grep {{ node_ip }} | cut -d, -f1"
|
2020-06-09 20:37:17 +08:00
|
|
|
register: etcd_member_id
|
2021-07-12 15:00:47 +08:00
|
|
|
ignore_errors: true # noqa ignore-errors
|
2020-06-09 20:37:17 +08:00
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
environment:
|
2020-07-20 22:26:51 +08:00
|
|
|
ETCDCTL_API: 3
|
2022-02-23 22:46:18 +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' }}"
|
|
|
|
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"
|
2020-06-09 20:37:17 +08:00
|
|
|
delegate_to: "{{ groups['etcd']|first }}"
|
2020-07-20 22:26:51 +08:00
|
|
|
when: inventory_hostname in groups['etcd']
|
2020-06-09 20:37:17 +08:00
|
|
|
|
2020-07-28 16:39:08 +08:00
|
|
|
- name: Remove etcd member from cluster
|
|
|
|
command: "{{ bin_dir }}/etcdctl member remove {{ etcd_member_id.stdout }}"
|
2020-06-09 20:37:17 +08:00
|
|
|
environment:
|
2020-07-20 22:26:51 +08:00
|
|
|
ETCDCTL_API: 3
|
2022-02-23 22:46:18 +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' }}"
|
|
|
|
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"
|
2020-06-09 20:37:17 +08:00
|
|
|
delegate_to: "{{ groups['etcd']|first }}"
|
|
|
|
when:
|
|
|
|
- inventory_hostname in groups['etcd']
|
|
|
|
- etcd_member_id.stdout | length > 0
|