2019-04-29 08:40:20 +00:00
|
|
|
---
|
2020-07-28 08:39:08 +00:00
|
|
|
- name: Get etcd endpoint health
|
|
|
|
command: "{{ bin_dir }}/etcdctl endpoint health"
|
2020-02-11 09:38:01 +00:00
|
|
|
register: etcd_endpoint_health
|
2021-07-12 07:00:47 +00:00
|
|
|
ignore_errors: true # noqa ignore-errors
|
2020-02-11 09:38:01 +00:00
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
environment:
|
2020-07-01 11:56:16 +00:00
|
|
|
ETCDCTL_API: 3
|
|
|
|
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 09:38:01 +00:00
|
|
|
when:
|
|
|
|
- groups['broken_etcd']
|
|
|
|
|
|
|
|
- name: Set healthy fact
|
|
|
|
set_fact:
|
2020-03-20 21:22:06 +00:00
|
|
|
healthy: "{{ etcd_endpoint_health.stderr is match('Error: unhealthy cluster') }}"
|
2020-02-11 09:38:01 +00:00
|
|
|
when:
|
|
|
|
- groups['broken_etcd']
|
|
|
|
|
|
|
|
- name: Set has_quorum fact
|
|
|
|
set_fact:
|
2021-10-26 22:23:09 +00: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-18 17:29:04 +00:00
|
|
|
when:
|
|
|
|
- groups['broken_etcd']
|
2019-04-29 08:40:20 +00:00
|
|
|
|
|
|
|
- include_tasks: recover_lost_quorum.yml
|
|
|
|
when:
|
2020-02-11 09:38:01 +00: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 07:00:47 +00:00
|
|
|
ignore_errors: true # noqa ignore-errors
|
2020-02-11 09:38:01 +00:00
|
|
|
when:
|
|
|
|
- groups['broken_etcd']
|
|
|
|
- has_quorum
|
|
|
|
|
|
|
|
- name: Delete old certificates
|
2021-07-12 07:00:47 +00:00
|
|
|
# noqa 302 ignore-error - rm is ok here for now
|
2020-02-11 09:38:01 +00:00
|
|
|
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:
|
|
|
|
- groups['broken_etcd']
|
|
|
|
- "item.rc != 0 and not 'No such file or directory' in item.stderr"
|
|
|
|
|
2020-07-28 08:39:08 +00:00
|
|
|
- name: Get etcd cluster members
|
|
|
|
command: "{{ bin_dir }}/etcdctl member list"
|
2020-02-11 09:38:01 +00:00
|
|
|
register: member_list
|
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
environment:
|
2020-07-01 11:56:16 +00:00
|
|
|
ETCDCTL_API: 3
|
|
|
|
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 09:38:01 +00:00
|
|
|
when:
|
|
|
|
- groups['broken_etcd']
|
|
|
|
- not healthy
|
|
|
|
- has_quorum
|
|
|
|
|
2020-07-28 08:39:08 +00:00
|
|
|
- name: Remove broken cluster members
|
|
|
|
command: "{{ bin_dir }}/etcdctl member remove {{ item[1].replace(' ','').split(',')[0] }}"
|
2020-02-11 09:38:01 +00:00
|
|
|
environment:
|
2020-07-01 11:56:16 +00:00
|
|
|
ETCDCTL_API: 3
|
|
|
|
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 09:38:01 +00:00
|
|
|
with_nested:
|
|
|
|
- "{{ groups['broken_etcd'] }}"
|
|
|
|
- "{{ member_list.stdout_lines }}"
|
|
|
|
when:
|
|
|
|
- groups['broken_etcd']
|
|
|
|
- not healthy
|
|
|
|
- has_quorum
|
|
|
|
- hostvars[item[0]]['etcd_member_name'] == item[1].replace(' ','').split(',')[2]
|