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.

168 lines
6.1 KiB

  1. ---
  2. - name: Configure | Check if etcd cluster is healthy
  3. shell: "set -o pipefail && {{ bin_dir }}/etcdctl endpoint --cluster status && {{ bin_dir }}/etcdctl endpoint --cluster health 2>&1 | grep -v 'Error: unhealthy cluster' >/dev/null"
  4. args:
  5. executable: /bin/bash
  6. register: etcd_cluster_is_healthy
  7. failed_when: false
  8. changed_when: false
  9. check_mode: no
  10. run_once: yes
  11. when: is_etcd_master and etcd_cluster_setup
  12. tags:
  13. - facts
  14. environment:
  15. ETCDCTL_API: 3
  16. ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  17. ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  18. ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
  19. ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
  20. - name: Configure | Check if etcd-events cluster is healthy
  21. shell: "set -o pipefail && {{ bin_dir }}/etcdctl endpoint --cluster status && {{ bin_dir }}/etcdctl endpoint --cluster health 2>&1 | grep -v 'Error: unhealthy cluster' >/dev/null"
  22. args:
  23. executable: /bin/bash
  24. register: etcd_events_cluster_is_healthy
  25. failed_when: false
  26. changed_when: false
  27. check_mode: no
  28. run_once: yes
  29. when: is_etcd_master and etcd_events_cluster_setup
  30. tags:
  31. - facts
  32. environment:
  33. ETCDCTL_API: 3
  34. ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  35. ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  36. ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
  37. ETCDCTL_ENDPOINTS: "{{ etcd_events_access_addresses }}"
  38. - include_tasks: refresh_config.yml
  39. when: is_etcd_master
  40. - name: Configure | Copy etcd.service systemd file
  41. template:
  42. src: "etcd-{{ etcd_deployment_type }}.service.j2"
  43. dest: /etc/systemd/system/etcd.service
  44. backup: yes
  45. mode: 0644
  46. when: is_etcd_master and etcd_cluster_setup
  47. - name: Configure | Copy etcd-events.service systemd file
  48. template:
  49. src: "etcd-events-{{ etcd_deployment_type }}.service.j2"
  50. dest: /etc/systemd/system/etcd-events.service
  51. backup: yes
  52. mode: 0644
  53. when: is_etcd_master and etcd_events_cluster_setup
  54. - name: Configure | reload systemd
  55. systemd:
  56. daemon_reload: true
  57. when: is_etcd_master
  58. # when scaling new etcd will fail to start
  59. - name: Configure | Ensure etcd is running
  60. service:
  61. name: etcd
  62. state: started
  63. enabled: yes
  64. ignore_errors: "{{ etcd_cluster_is_healthy.rc == 0 }}" # noqa ignore-errors
  65. when: is_etcd_master and etcd_cluster_setup
  66. # when scaling new etcd will fail to start
  67. - name: Configure | Ensure etcd-events is running
  68. service:
  69. name: etcd-events
  70. state: started
  71. enabled: yes
  72. ignore_errors: "{{ etcd_events_cluster_is_healthy.rc != 0 }}" # noqa ignore-errors
  73. when: is_etcd_master and etcd_events_cluster_setup
  74. - name: Configure | Wait for etcd cluster to be healthy
  75. shell: "set -o pipefail && {{ bin_dir }}/etcdctl endpoint --cluster status && {{ bin_dir }}/etcdctl endpoint --cluster health 2>&1 | grep -v 'Error: unhealthy cluster' >/dev/null"
  76. args:
  77. executable: /bin/bash
  78. register: etcd_cluster_is_healthy
  79. until: etcd_cluster_is_healthy.rc == 0
  80. retries: "{{ etcd_retries }}"
  81. delay: "{{ retry_stagger | random + 3 }}"
  82. changed_when: false
  83. check_mode: no
  84. run_once: yes
  85. when:
  86. - is_etcd_master
  87. - etcd_cluster_setup
  88. tags:
  89. - facts
  90. environment:
  91. ETCDCTL_API: 3
  92. ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  93. ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  94. ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
  95. ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
  96. - name: Configure | Wait for etcd-events cluster to be healthy
  97. shell: "set -o pipefail && {{ bin_dir }}/etcdctl endpoint --cluster status && {{ bin_dir }}/etcdctl endpoint --cluster health 2>&1 | grep -v 'Error: unhealthy cluster' >/dev/null"
  98. args:
  99. executable: /bin/bash
  100. register: etcd_events_cluster_is_healthy
  101. until: etcd_events_cluster_is_healthy.rc == 0
  102. retries: "{{ etcd_retries }}"
  103. delay: "{{ retry_stagger | random + 3 }}"
  104. changed_when: false
  105. check_mode: no
  106. run_once: yes
  107. when:
  108. - is_etcd_master
  109. - etcd_events_cluster_setup
  110. tags:
  111. - facts
  112. environment:
  113. ETCDCTL_API: 3
  114. ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  115. ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  116. ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
  117. ETCDCTL_ENDPOINTS: "{{ etcd_events_access_addresses }}"
  118. - name: Configure | Check if member is in etcd cluster
  119. shell: "{{ bin_dir }}/etcdctl member list | grep -q {{ etcd_access_address }}"
  120. register: etcd_member_in_cluster
  121. ignore_errors: true # noqa ignore-errors
  122. changed_when: false
  123. check_mode: no
  124. when: is_etcd_master and etcd_cluster_setup
  125. tags:
  126. - facts
  127. environment:
  128. ETCDCTL_API: 3
  129. ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  130. ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  131. ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
  132. ETCDCTL_ENDPOINTS: "{{ etcd_access_addresses }}"
  133. - name: Configure | Check if member is in etcd-events cluster
  134. shell: "{{ bin_dir }}/etcdctl member list | grep -q {{ etcd_access_address }}"
  135. register: etcd_events_member_in_cluster
  136. ignore_errors: true # noqa ignore-errors
  137. changed_when: false
  138. check_mode: no
  139. when: is_etcd_master and etcd_events_cluster_setup
  140. tags:
  141. - facts
  142. environment:
  143. ETCDCTL_API: 3
  144. ETCDCTL_CERT: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  145. ETCDCTL_KEY: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  146. ETCDCTL_CACERT: "{{ etcd_cert_dir }}/ca.pem"
  147. ETCDCTL_ENDPOINTS: "{{ etcd_events_access_addresses }}"
  148. - name: Configure | Join member(s) to etcd cluster one at a time
  149. include_tasks: join_etcd_member.yml
  150. with_items: "{{ groups['etcd'] }}"
  151. when: inventory_hostname == item and etcd_cluster_setup and etcd_member_in_cluster.rc != 0 and etcd_cluster_is_healthy.rc == 0
  152. - name: Configure | Join member(s) to etcd-events cluster one at a time
  153. include_tasks: join_etcd-events_member.yml
  154. with_items: "{{ groups['etcd'] }}"
  155. when: inventory_hostname == item and etcd_events_cluster_setup and etcd_events_member_in_cluster.rc != 0 and etcd_events_cluster_is_healthy.rc == 0