2018-03-01 16:39:14 +08:00
|
|
|
---
|
2018-04-02 00:58:08 +08:00
|
|
|
- name: Join Member | Add member to etcd cluster
|
2020-07-01 19:56:16 +08:00
|
|
|
shell: "{{ bin_dir }}/etcdctl member add {{ etcd_member_name }} {{ etcd_peer_url }}"
|
2018-03-01 16:39:14 +08:00
|
|
|
register: member_add_result
|
|
|
|
until: member_add_result.rc == 0
|
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:
|
2020-07-01 19:56:16 +08:00
|
|
|
ETCDCTL_API: 2
|
|
|
|
ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
|
2018-04-01 02:06:09 +08:00
|
|
|
ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
|
|
|
|
ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
|
2018-11-02 23:27:53 +08:00
|
|
|
ETCDCTL_CA_FILE: "{{ etcd_cert_dir }}/ca.pem"
|
2018-03-01 16:39:14 +08:00
|
|
|
|
|
|
|
- include_tasks: refresh_config.yml
|
|
|
|
vars:
|
|
|
|
etcd_peer_addresses: >-
|
|
|
|
{% for host in groups['etcd'] -%}
|
|
|
|
{%- if hostvars[host]['etcd_member_in_cluster'].rc == 0 -%}
|
2019-03-05 19:04:39 +08:00
|
|
|
{{ "etcd"+loop.index|string }}=https://{{ hostvars[host].access_ip | 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 -%}
|
|
|
|
|
2018-04-02 00:58:08 +08:00
|
|
|
- name: Join Member | Ensure member is in etcd cluster
|
2020-07-01 19:56:16 +08:00
|
|
|
shell: "{{ bin_dir }}/etcdctl --no-sync member list | grep -q {{ etcd_access_address }}"
|
2018-03-01 16:39:14 +08:00
|
|
|
register: etcd_member_in_cluster
|
|
|
|
changed_when: false
|
|
|
|
check_mode: no
|
|
|
|
tags:
|
|
|
|
- facts
|
|
|
|
environment:
|
2020-07-01 19:56:16 +08:00
|
|
|
ETCDCTL_API: 2
|
|
|
|
ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
|
2018-04-01 02:06:09 +08:00
|
|
|
ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
|
|
|
|
ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
|
2018-11-02 23:27:53 +08:00
|
|
|
ETCDCTL_CA_FILE: "{{ etcd_cert_dir }}/ca.pem"
|
2020-04-08 16:27:43 +08:00
|
|
|
|
|
|
|
- name: Configure | Ensure etcd is running
|
|
|
|
service:
|
|
|
|
name: etcd
|
|
|
|
state: started
|
|
|
|
enabled: yes
|