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.

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