evaluate_groups.yml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. ---
  2. - name: Populate config host groups
  3. hosts: localhost
  4. connection: local
  5. gather_facts: no
  6. tasks:
  7. - name: Load group name mapping variables
  8. include_vars: vars/cluster_hosts.yml
  9. - name: Evaluate groups - g_etcd_hosts or g_new_etcd_hosts required
  10. fail:
  11. msg: This playbook requires g_etcd_hosts or g_new_etcd_hosts to be set
  12. when: g_etcd_hosts is not defined and g_new_etcd_hosts is not defined
  13. - name: Evaluate groups - g_master_hosts or g_new_master_hosts required
  14. fail:
  15. msg: This playbook requires g_master_hosts or g_new_master_hosts to be set
  16. when: g_master_hosts is not defined and g_new_master_hosts is not defined
  17. - name: Evaluate groups - g_node_hosts or g_new_node_hosts required
  18. fail:
  19. msg: This playbook requires g_node_hosts or g_new_node_hosts to be set
  20. when: g_node_hosts is not defined and g_new_node_hosts is not defined
  21. - name: Evaluate groups - g_lb_hosts required
  22. fail:
  23. msg: This playbook requires g_lb_hosts to be set
  24. when: g_lb_hosts is not defined
  25. - name: Evaluate groups - g_nfs_hosts required
  26. fail:
  27. msg: This playbook requires g_nfs_hosts to be set
  28. when: g_nfs_hosts is not defined
  29. - name: Evaluate groups - g_nfs_hosts is single host
  30. fail:
  31. msg: The nfs group must be limited to one host
  32. when: g_nfs_hosts | default([]) | length > 1
  33. - name: Evaluate groups - g_glusterfs_hosts required
  34. fail:
  35. msg: This playbook requires g_glusterfs_hosts to be set
  36. when: g_glusterfs_hosts is not defined
  37. - name: Evaluate groups - Fail if no etcd hosts group is defined
  38. fail:
  39. msg: >
  40. Running etcd as an embedded service is no longer supported. If this is a
  41. new install please define an 'etcd' group with either one, three or five
  42. hosts. These hosts may be the same hosts as your masters. If this is an
  43. upgrade please see https://docs.openshift.com/container-platform/latest/install_config/upgrading/migrating_embedded_etcd.html
  44. for documentation on how to migrate from embedded to external etcd.
  45. when:
  46. - g_etcd_hosts | default([]) | length == 0
  47. - not (openshift_node_bootstrap | default(True))
  48. - name: Evaluate oo_all_hosts
  49. add_host:
  50. name: "{{ item }}"
  51. groups: oo_all_hosts
  52. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  53. ansible_become: "{{ g_sudo | default(omit) }}"
  54. with_items: "{{ g_all_hosts | default([]) }}"
  55. changed_when: no
  56. - name: Evaluate oo_masters
  57. add_host:
  58. name: "{{ item }}"
  59. groups: oo_masters
  60. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  61. ansible_become: "{{ g_sudo | default(omit) }}"
  62. with_items: "{{ g_master_hosts | union(g_new_master_hosts) | default([]) }}"
  63. changed_when: no
  64. - name: Evaluate oo_first_master
  65. add_host:
  66. name: "{{ g_master_hosts[0] }}"
  67. groups: oo_first_master
  68. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  69. ansible_become: "{{ g_sudo | default(omit) }}"
  70. when: g_master_hosts|length > 0
  71. changed_when: no
  72. - name: Evaluate oo_new_etcd_to_config
  73. add_host:
  74. name: "{{ item }}"
  75. groups: oo_new_etcd_to_config
  76. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  77. ansible_become: "{{ g_sudo | default(omit) }}"
  78. with_items: "{{ g_new_etcd_hosts | default([]) }}"
  79. changed_when: no
  80. - name: Evaluate oo_masters_to_config
  81. add_host:
  82. name: "{{ item }}"
  83. groups: oo_masters_to_config
  84. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  85. ansible_become: "{{ g_sudo | default(omit) }}"
  86. with_items: "{{ g_new_master_hosts | default(g_master_hosts | default([], true), true) }}"
  87. changed_when: no
  88. - name: Evaluate oo_etcd_to_config
  89. add_host:
  90. name: "{{ item }}"
  91. groups: oo_etcd_to_config
  92. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  93. ansible_become: "{{ g_sudo | default(omit) }}"
  94. with_items: "{{ g_etcd_hosts | default([]) }}"
  95. changed_when: no
  96. - name: Evaluate oo_first_etcd
  97. add_host:
  98. name: "{{ g_etcd_hosts[0] }}"
  99. groups: oo_first_etcd
  100. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  101. ansible_become: "{{ g_sudo | default(omit) }}"
  102. when: g_etcd_hosts|length > 0
  103. changed_when: no
  104. # We use two groups one for hosts we're upgrading which doesn't include embedded etcd
  105. # The other for backing up which includes the embedded etcd host, there's no need to
  106. # upgrade embedded etcd that just happens when the master is updated.
  107. - name: Evaluate oo_etcd_hosts_to_upgrade
  108. add_host:
  109. name: "{{ item }}"
  110. groups: oo_etcd_hosts_to_upgrade
  111. with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 else [] }}"
  112. changed_when: False
  113. - name: Evaluate oo_etcd_hosts_to_backup
  114. add_host:
  115. name: "{{ item }}"
  116. groups: oo_etcd_hosts_to_backup
  117. with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 else (groups.oo_first_master | default([])) }}"
  118. changed_when: False
  119. - name: Evaluate oo_nodes_to_config
  120. add_host:
  121. name: "{{ item }}"
  122. groups: oo_nodes_to_config
  123. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  124. ansible_become: "{{ g_sudo | default(omit) }}"
  125. with_items: "{{ g_new_node_hosts | default(g_node_hosts | default([], true), true) }}"
  126. changed_when: no
  127. - name: Evaluate oo_nodes_to_bootstrap
  128. add_host:
  129. name: "{{ item }}"
  130. groups: oo_nodes_to_bootstrap
  131. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  132. ansible_become: "{{ g_sudo | default(omit) }}"
  133. with_items: "{{ g_new_node_hosts | default(g_node_hosts | default([], true), true) }}"
  134. changed_when: no
  135. when: hostvars[item].openshift_node_bootstrap | default(True) | bool
  136. - name: Add masters to oo_nodes_to_bootstrap
  137. add_host:
  138. name: "{{ item }}"
  139. groups: oo_nodes_to_bootstrap
  140. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  141. ansible_become: "{{ g_sudo | default(omit) }}"
  142. with_items: "{{ groups.oo_masters | default([]) }}"
  143. changed_when: no
  144. - name: Evaluate oo_lb_to_config
  145. add_host:
  146. name: "{{ item }}"
  147. groups: oo_lb_to_config
  148. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  149. ansible_become: "{{ g_sudo | default(omit) }}"
  150. with_items: "{{ g_lb_hosts | default([]) }}"
  151. changed_when: no
  152. - name: Evaluate oo_nfs_to_config
  153. add_host:
  154. name: "{{ item }}"
  155. groups: oo_nfs_to_config
  156. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  157. ansible_become: "{{ g_sudo | default(omit) }}"
  158. with_items: "{{ g_nfs_hosts | default([]) }}"
  159. changed_when: no
  160. - name: Evaluate oo_glusterfs_to_config
  161. add_host:
  162. name: "{{ item }}"
  163. groups: oo_glusterfs_to_config
  164. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  165. ansible_become: "{{ g_sudo | default(omit) }}"
  166. with_items: "{{ g_glusterfs_hosts | union(g_glusterfs_registry_hosts | default([])) }}"
  167. changed_when: no
  168. - name: Evaluate oo_etcd_to_migrate
  169. add_host:
  170. name: "{{ item }}"
  171. groups: oo_etcd_to_migrate
  172. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  173. ansible_become: "{{ g_sudo | default(omit) }}"
  174. with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config | default([]) | length != 0 else (groups.oo_first_master |default([]))}}"
  175. changed_when: no