2018-03-01 16:39:14 +08:00
|
|
|
---
|
2023-06-30 17:51:57 +08:00
|
|
|
- name: Join Member | Add member to etcd cluster
|
2023-06-26 18:15:45 +08:00
|
|
|
command: "{{ bin_dir }}/etcdctl member add {{ etcd_member_name }} --peer-urls={{ etcd_peer_url }}"
|
2018-03-01 16:39:14 +08:00
|
|
|
register: member_add_result
|
2020-08-27 17:33:01 +08:00
|
|
|
until: member_add_result.rc == 0 or 'Peer URLs already exists' in member_add_result.stderr
|
|
|
|
failed_when: member_add_result.rc != 0 and 'Peer URLs already exists' not in member_add_result.stderr
|
2020-02-11 17:38:01 +08:00
|
|
|
retries: "{{ etcd_retries }}"
|
2018-03-01 16:39:14 +08:00
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
environment:
|
2023-06-26 18:15:45 +08:00
|
|
|
ETCDCTL_API: "3"
|
2020-07-20 22:26:51 +08:00
|
|
|
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-07-01 19:56:16 +08:00
|
|
|
ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
|
2018-03-01 16:39:14 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Join Member | Refresh etcd config
|
|
|
|
include_tasks: refresh_config.yml
|
2018-03-01 16:39:14 +08:00
|
|
|
vars:
|
2023-07-05 11:36:54 +08:00
|
|
|
# noqa: jinja[spacing]
|
2018-03-01 16:39:14 +08:00
|
|
|
etcd_peer_addresses: >-
|
|
|
|
{% for host in groups['etcd'] -%}
|
|
|
|
{%- if hostvars[host]['etcd_member_in_cluster'].rc == 0 -%}
|
2023-07-05 11:36:54 +08:00
|
|
|
{{ "etcd" + loop.index | string }}=https://{{ hostvars[host].etcd_access_address | default(hostvars[host].ip | default(fallback_ips[host])) }}:2380,
|
2018-03-01 16:39:14 +08:00
|
|
|
{%- endif -%}
|
|
|
|
{%- if loop.last -%}
|
|
|
|
{{ etcd_member_name }}={{ etcd_peer_url }}
|
|
|
|
{%- endif -%}
|
|
|
|
{%- endfor -%}
|
|
|
|
|
2020-08-31 18:20:20 +08:00
|
|
|
- name: Join Member | Ensure member is in etcd cluster
|
2023-07-14 12:43:29 +08:00
|
|
|
shell: "set -o pipefail && {{ bin_dir }}/etcdctl member list | grep -w {{ etcd_access_address }} >/dev/null"
|
2020-08-31 18:20:20 +08:00
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
2018-03-01 16:39:14 +08:00
|
|
|
register: etcd_member_in_cluster
|
|
|
|
changed_when: false
|
2024-08-28 13:30:56 +08:00
|
|
|
check_mode: false
|
2021-10-27 06:23:09 +08:00
|
|
|
retries: "{{ etcd_retries }}"
|
|
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
|
|
until: etcd_member_in_cluster.rc == 0
|
2018-03-01 16:39:14 +08:00
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
environment:
|
2023-06-26 18:15:45 +08:00
|
|
|
ETCDCTL_API: "3"
|
2020-07-20 22:26:51 +08:00
|
|
|
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-07-01 19:56:16 +08:00
|
|
|
ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
|
2020-04-08 16:27:43 +08:00
|
|
|
|
|
|
|
- name: Configure | Ensure etcd is running
|
|
|
|
service:
|
|
|
|
name: etcd
|
|
|
|
state: started
|
2024-08-28 13:30:56 +08:00
|
|
|
enabled: true
|