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.

133 lines
4.9 KiB

  1. ---
  2. - name: Configure | Check if etcd cluster is healthy
  3. shell: "{{ bin_dir }}/etcdctl --endpoints={{ etcd_access_addresses }} cluster-health | grep -q 'cluster is healthy'"
  4. register: etcd_cluster_is_healthy
  5. ignore_errors: true
  6. changed_when: false
  7. check_mode: no
  8. when: is_etcd_master and etcd_cluster_setup
  9. tags:
  10. - facts
  11. environment:
  12. ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  13. ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  14. - name: Configure | Check if etcd-events cluster is healthy
  15. shell: "{{ bin_dir }}/etcdctl --endpoints={{ etcd_events_access_addresses }} cluster-health | grep -q 'cluster is healthy'"
  16. register: etcd_events_cluster_is_healthy
  17. ignore_errors: true
  18. changed_when: false
  19. check_mode: no
  20. when: is_etcd_master and etcd_events_cluster_setup
  21. tags:
  22. - facts
  23. environment:
  24. ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  25. ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  26. - include_tasks: refresh_config.yml
  27. when: is_etcd_master
  28. - name: Configure | Copy etcd.service systemd file
  29. template:
  30. src: "etcd-{{ etcd_deployment_type }}.service.j2"
  31. dest: /etc/systemd/system/etcd.service
  32. backup: yes
  33. when: is_etcd_master and etcd_cluster_setup
  34. - name: Configure | Copy etcd-events.service systemd file
  35. template:
  36. src: "etcd-events-{{ etcd_deployment_type }}.service.j2"
  37. dest: /etc/systemd/system/etcd-events.service
  38. backup: yes
  39. when: is_etcd_master and etcd_events_cluster_setup
  40. - name: Configure | reload systemd
  41. command: systemctl daemon-reload
  42. when: is_etcd_master
  43. - name: Configure | Ensure etcd is running
  44. service:
  45. name: etcd
  46. state: started
  47. enabled: yes
  48. when: is_etcd_master and etcd_cluster_setup
  49. - name: Configure | Ensure etcd-events is running
  50. service:
  51. name: etcd-events
  52. state: started
  53. enabled: yes
  54. when: is_etcd_master and etcd_events_cluster_setup
  55. - name: Configure | Check if etcd cluster is healthy
  56. shell: "{{ bin_dir }}/etcdctl --endpoints={{ etcd_access_addresses }} cluster-health | grep -q 'cluster is healthy'"
  57. register: etcd_cluster_is_healthy
  58. until: etcd_cluster_is_healthy.rc == 0
  59. retries: 4
  60. delay: "{{ retry_stagger | random + 3 }}"
  61. ignore_errors: false
  62. changed_when: false
  63. check_mode: no
  64. when: is_etcd_master and etcd_cluster_setup
  65. tags:
  66. - facts
  67. environment:
  68. ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  69. ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  70. - name: Configure | Check if etcd-events cluster is healthy
  71. shell: "{{ bin_dir }}/etcdctl --endpoints={{ etcd_events_access_addresses }} cluster-health | grep -q 'cluster is healthy'"
  72. register: etcd_events_cluster_is_healthy
  73. until: etcd_events_cluster_is_healthy.rc == 0
  74. retries: 4
  75. delay: "{{ retry_stagger | random + 3 }}"
  76. ignore_errors: false
  77. changed_when: false
  78. check_mode: no
  79. when: is_etcd_master and etcd_events_cluster_setup
  80. tags:
  81. - facts
  82. environment:
  83. ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  84. ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  85. - name: Configure | Check if member is in etcd cluster
  86. shell: "{{ bin_dir }}/etcdctl --no-sync --endpoints={{ etcd_access_addresses }} member list | grep -q {{ etcd_access_address }}"
  87. register: etcd_member_in_cluster
  88. ignore_errors: true
  89. changed_when: false
  90. check_mode: no
  91. when: is_etcd_master and etcd_cluster_setup
  92. tags:
  93. - facts
  94. environment:
  95. ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  96. ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  97. - name: Configure | Check if member is in etcd-events cluster
  98. shell: "{{ bin_dir }}/etcdctl --no-sync --endpoints={{ etcd_events_access_addresses }} member list | grep -q {{ etcd_access_address }}"
  99. register: etcd_events_member_in_cluster
  100. ignore_errors: true
  101. changed_when: false
  102. check_mode: no
  103. when: is_etcd_master and etcd_events_cluster_setup
  104. tags:
  105. - facts
  106. environment:
  107. ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}.pem"
  108. ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ inventory_hostname }}-key.pem"
  109. - name: Configure | Join member(s) to etcd cluster one at a time
  110. include_tasks: join_etcd_member.yml
  111. vars:
  112. target_node: "{{ item }}"
  113. with_items: "{{ groups['etcd'] }}"
  114. when: inventory_hostname == item and etcd_cluster_setup and etcd_member_in_cluster.rc != 0 and etcd_cluster_is_healthy.rc == 0
  115. - name: Configure | Join member(s) to etcd-events cluster one at a time
  116. include_tasks: join_etcd-events_member.yml
  117. vars:
  118. target_node: "{{ item }}"
  119. with_items: "{{ groups['etcd'] }}"
  120. 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