kolla-ansible/ansible/roles/etcd/tasks/lookup_leader.yml
Jan Gutter ed3b27cc92 etcd: Add support for more scenarios
This commit addresses a few shortcomings in the etcd service:
  * Adding or removing etcd nodes required manual intervention.

  * The etcd service would have brief outages during upgrades or
    reconfigures because restarts weren't always serialised.

This makes the etcd service follow a similar pattern to mariadb:
  * There is now a distiction between bootstrapping the cluster
    and adding / removing another member.

  * This more closely follows etcd's upstream bootstrapping
    guidelines.

  * The etcd role now serialises restarts internally so the
    kolla_serial pattern is no longer appropriate (or necessary).

This does not remove the need for manual intervention in all
failure modes: the documentation has been updated to address the
most common issues.

Note that there's repetition in the container specifications: this
is somewhat deliberate. In a future cleanup, it's intended to reduce
the duplication.

Change-Id: I39829ba0c5894f8e549f9b83b416e6db4fafd96f
2023-11-28 18:43:56 +01:00

42 lines
1.4 KiB
YAML

---
# NOTE(jan.gutter): These tasks assume a cluster is running
- name: Check for the etcd leader
vars:
service_name: "etcd"
service: "{{ etcd_services[service_name] }}"
become: true
# NOTE(jan.gutter): We need to set the ETCD environment vars here to
# handle an upgrade scenario from older etcd containers. These can be
# removed once the new workflow has been in place for a cycle or two.
command: >-
{{ kolla_container_engine }} exec
-e ETCDCTL_API=3
-e ETCDCTL_ENDPOINTS="{{ etcd_client_internal_endpoint }}"
-e ETCDCTL_WRITE_OUT="json"
{{ service.container_name }}
etcdctl endpoint status
changed_when: false
when:
- inventory_hostname in (groups.etcd_had_volume_True | default([]))
register: etcd_endpoint_status_result
- name: Divide hosts by their etcd leader status
vars:
etcd_endpoint_status: >-
{{ etcd_endpoint_status_result.stdout | default('[]') | from_json }}
etcd_member_id: >-
{{ etcd_endpoint_status[0]['Status']['header']['member_id']
| default('') }}
etcd_leader_id: >-
{{ etcd_endpoint_status[0]['Status']['leader']
| default('none') }}
group_by:
key: etcd_is_leader_{{ etcd_member_id == etcd_leader_id }}
changed_when: false
- name: Set the etcd cluster leader
set_fact:
etcd_cluster_leader: "{{ groups.etcd_is_leader_True | sort | first }}"
when: groups.etcd_is_leader_True is defined
changed_when: false