You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.8 KiB

  1. ---
  2. - name: Join Member | Add member to cluster
  3. shell: "{{ bin_dir }}/etcdctl --endpoints={{ etcd_access_addresses }} member add {{ etcd_member_name }} {{ etcd_peer_url }}"
  4. register: member_add_result
  5. until: member_add_result.rc == 0
  6. retries: 4
  7. delay: "{{ retry_stagger | random + 3 }}"
  8. when: target_node == inventory_hostname
  9. environment:
  10. ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}.pem"
  11. ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}-key.pem"
  12. - include_tasks: refresh_config.yml
  13. vars:
  14. etcd_peer_addresses: >-
  15. {% for host in groups['etcd'] -%}
  16. {%- if hostvars[host]['etcd_member_in_cluster'].rc == 0 -%}
  17. {{ "etcd"+loop.index|string }}=https://{{ hostvars[host].access_ip | default(hostvars[host].ip | default(hostvars[host].ansible_default_ipv4['address'])) }}:2380,
  18. {%- endif -%}
  19. {%- if loop.last -%}
  20. {{ etcd_member_name }}={{ etcd_peer_url }}
  21. {%- endif -%}
  22. {%- endfor -%}
  23. when: target_node == inventory_hostname
  24. - name: Join Member | reload systemd
  25. command: systemctl daemon-reload
  26. when: target_node == inventory_hostname
  27. - name: Join Member | Ensure etcd is running
  28. service:
  29. name: etcd
  30. state: started
  31. enabled: yes
  32. when: target_node == inventory_hostname
  33. - name: Join Member | Ensure member is in cluster
  34. shell: "{{ bin_dir }}/etcdctl --no-sync --endpoints={{ etcd_access_addresses }} member list | grep -q {{ etcd_access_address }}"
  35. register: etcd_member_in_cluster
  36. changed_when: false
  37. check_mode: no
  38. tags:
  39. - facts
  40. when: target_node == inventory_hostname
  41. environment:
  42. ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}.pem"
  43. ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/node-{{ inventory_hostname }}-key.pem"