2019-04-29 16:40:20 +08:00
|
|
|
---
|
2020-07-28 16:39:08 +08:00
|
|
|
- name: Get etcd endpoint health
|
|
|
|
command: "{{ bin_dir }}/etcdctl endpoint health"
|
2020-02-11 17:38:01 +08:00
|
|
|
register: etcd_endpoint_health
|
2021-07-12 15:00:47 +08:00
|
|
|
ignore_errors: true # noqa ignore-errors
|
2020-02-11 17:38:01 +08:00
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
environment:
|
2023-06-26 18:15:45 +08:00
|
|
|
ETCDCTL_API: "3"
|
2020-07-01 19:56:16 +08:00
|
|
|
ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
|
|
|
|
ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
|
|
|
|
ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
|
|
|
|
ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
|
2020-02-11 17:38:01 +08:00
|
|
|
when:
|
2023-09-06 01:42:52 +08:00
|
|
|
- groups['broken_etcd']
|
2020-02-11 17:38:01 +08:00
|
|
|
|
|
|
|
- name: Set healthy fact
|
|
|
|
set_fact:
|
2020-03-21 05:22:06 +08:00
|
|
|
healthy: "{{ etcd_endpoint_health.stderr is match('Error: unhealthy cluster') }}"
|
2020-02-11 17:38:01 +08:00
|
|
|
when:
|
2023-09-06 01:42:52 +08:00
|
|
|
- groups['broken_etcd']
|
2020-02-11 17:38:01 +08:00
|
|
|
|
|
|
|
- name: Set has_quorum fact
|
|
|
|
set_fact:
|
2021-10-27 06:23:09 +08:00
|
|
|
has_quorum: "{{ etcd_endpoint_health.stdout_lines | select('match', '.*is healthy.*') | list | length >= etcd_endpoint_health.stderr_lines | select('match', '.*is unhealthy.*') | list | length }}"
|
2021-05-19 01:29:04 +08:00
|
|
|
when:
|
2023-09-06 01:42:52 +08:00
|
|
|
- groups['broken_etcd']
|
2019-04-29 16:40:20 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Recover lost etcd quorum
|
|
|
|
include_tasks: recover_lost_quorum.yml
|
2019-04-29 16:40:20 +08:00
|
|
|
when:
|
2020-02-11 17:38:01 +08:00
|
|
|
- groups['broken_etcd']
|
|
|
|
- not has_quorum
|
|
|
|
|
|
|
|
- name: Remove etcd data dir
|
|
|
|
file:
|
|
|
|
path: "{{ etcd_data_dir }}"
|
|
|
|
state: absent
|
|
|
|
delegate_to: "{{ item }}"
|
|
|
|
with_items: "{{ groups['broken_etcd'] }}"
|
2021-07-12 15:00:47 +08:00
|
|
|
ignore_errors: true # noqa ignore-errors
|
2024-01-23 00:22:27 +08:00
|
|
|
ignore_unreachable: true
|
2020-02-11 17:38:01 +08:00
|
|
|
when:
|
2023-09-06 01:42:52 +08:00
|
|
|
- groups['broken_etcd']
|
2020-02-11 17:38:01 +08:00
|
|
|
- has_quorum
|
|
|
|
|
|
|
|
- name: Delete old certificates
|
|
|
|
shell: "rm {{ etcd_cert_dir }}/*{{ item }}*"
|
|
|
|
with_items: "{{ groups['broken_etcd'] }}"
|
|
|
|
register: delete_old_cerificates
|
|
|
|
ignore_errors: true
|
|
|
|
when: groups['broken_etcd']
|
|
|
|
|
|
|
|
- name: Fail if unable to delete old certificates
|
|
|
|
fail:
|
|
|
|
msg: "Unable to delete old certificates for: {{ item.item }}"
|
|
|
|
loop: "{{ delete_old_cerificates.results }}"
|
|
|
|
changed_when: false
|
|
|
|
when:
|
2023-09-06 01:42:52 +08:00
|
|
|
- groups['broken_etcd']
|
2020-02-11 17:38:01 +08:00
|
|
|
- "item.rc != 0 and not 'No such file or directory' in item.stderr"
|
|
|
|
|
2020-07-28 16:39:08 +08:00
|
|
|
- name: Get etcd cluster members
|
|
|
|
command: "{{ bin_dir }}/etcdctl member list"
|
2020-02-11 17:38:01 +08:00
|
|
|
register: member_list
|
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
environment:
|
2023-06-26 18:15:45 +08:00
|
|
|
ETCDCTL_API: "3"
|
2020-07-01 19:56:16 +08:00
|
|
|
ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
|
|
|
|
ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
|
|
|
|
ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
|
|
|
|
ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
|
2020-02-11 17:38:01 +08:00
|
|
|
when:
|
2023-09-06 01:42:52 +08:00
|
|
|
- groups['broken_etcd']
|
2020-02-11 17:38:01 +08:00
|
|
|
- not healthy
|
|
|
|
- has_quorum
|
|
|
|
|
2020-07-28 16:39:08 +08:00
|
|
|
- name: Remove broken cluster members
|
2023-07-05 11:36:54 +08:00
|
|
|
command: "{{ bin_dir }}/etcdctl member remove {{ item[1].replace(' ', '').split(',')[0] }}"
|
2020-02-11 17:38:01 +08:00
|
|
|
environment:
|
2023-06-26 18:15:45 +08:00
|
|
|
ETCDCTL_API: "3"
|
2020-07-01 19:56:16 +08:00
|
|
|
ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
|
|
|
|
ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
|
|
|
|
ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
|
|
|
|
ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
|
2020-02-11 17:38:01 +08:00
|
|
|
with_nested:
|
|
|
|
- "{{ groups['broken_etcd'] }}"
|
|
|
|
- "{{ member_list.stdout_lines }}"
|
|
|
|
when:
|
2023-09-06 01:42:52 +08:00
|
|
|
- groups['broken_etcd']
|
2020-02-11 17:38:01 +08:00
|
|
|
- not healthy
|
|
|
|
- has_quorum
|
2023-07-05 11:36:54 +08:00
|
|
|
- hostvars[item[0]]['etcd_member_name'] == item[1].replace(' ', '').split(',')[2]
|