evaluate_groups.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 oo_all_hosts
  38. add_host:
  39. name: "{{ item }}"
  40. groups: oo_all_hosts
  41. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  42. ansible_become: "{{ g_sudo | default(omit) }}"
  43. with_items: "{{ g_all_hosts | default([]) }}"
  44. changed_when: no
  45. - name: Evaluate oo_masters
  46. add_host:
  47. name: "{{ item }}"
  48. groups: oo_masters
  49. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  50. ansible_become: "{{ g_sudo | default(omit) }}"
  51. with_items: "{{ g_master_hosts | union(g_new_master_hosts) | default([]) }}"
  52. changed_when: no
  53. - name: Evaluate oo_first_master
  54. add_host:
  55. name: "{{ g_master_hosts[0] }}"
  56. groups: oo_first_master
  57. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  58. ansible_become: "{{ g_sudo | default(omit) }}"
  59. when: g_master_hosts|length > 0
  60. changed_when: no
  61. - name: Evaluate oo_new_etcd_to_config
  62. add_host:
  63. name: "{{ item }}"
  64. groups: oo_new_etcd_to_config
  65. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  66. ansible_become: "{{ g_sudo | default(omit) }}"
  67. with_items: "{{ g_new_etcd_hosts | default([]) }}"
  68. changed_when: no
  69. - name: Evaluate oo_masters_to_config
  70. add_host:
  71. name: "{{ item }}"
  72. groups: oo_masters_to_config
  73. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  74. ansible_become: "{{ g_sudo | default(omit) }}"
  75. with_items: "{{ g_new_master_hosts | default(g_master_hosts | default([], true), true) }}"
  76. changed_when: no
  77. - name: Evaluate oo_etcd_to_config
  78. add_host:
  79. name: "{{ item }}"
  80. groups: oo_etcd_to_config
  81. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  82. ansible_become: "{{ g_sudo | default(omit) }}"
  83. with_items: "{{ g_etcd_hosts | default([]) }}"
  84. changed_when: no
  85. - name: Evaluate oo_first_etcd
  86. add_host:
  87. name: "{{ g_etcd_hosts[0] }}"
  88. groups: oo_first_etcd
  89. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  90. ansible_become: "{{ g_sudo | default(omit) }}"
  91. when: g_etcd_hosts|length > 0
  92. changed_when: no
  93. # We use two groups one for hosts we're upgrading which doesn't include embedded etcd
  94. # The other for backing up which includes the embedded etcd host, there's no need to
  95. # upgrade embedded etcd that just happens when the master is updated.
  96. - name: Evaluate oo_etcd_hosts_to_upgrade
  97. add_host:
  98. name: "{{ item }}"
  99. groups: oo_etcd_hosts_to_upgrade
  100. with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 else [] }}"
  101. changed_when: False
  102. - name: Evaluate oo_etcd_hosts_to_backup
  103. add_host:
  104. name: "{{ item }}"
  105. groups: oo_etcd_hosts_to_backup
  106. 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([])) }}"
  107. changed_when: False
  108. - name: Evaluate oo_nodes_to_config
  109. add_host:
  110. name: "{{ item }}"
  111. groups: oo_nodes_to_config
  112. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  113. ansible_become: "{{ g_sudo | default(omit) }}"
  114. with_items: "{{ g_new_node_hosts | default(g_node_hosts | default([], true), true) }}"
  115. changed_when: no
  116. - name: Evaluate oo_nodes_to_bootstrap
  117. add_host:
  118. name: "{{ item }}"
  119. groups: oo_nodes_to_bootstrap
  120. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  121. ansible_become: "{{ g_sudo | default(omit) }}"
  122. with_items: "{{ g_new_node_hosts | default(g_node_hosts | default([], true), true) }}"
  123. changed_when: no
  124. - name: Add masters to oo_nodes_to_bootstrap
  125. add_host:
  126. name: "{{ item }}"
  127. groups: oo_nodes_to_bootstrap
  128. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  129. ansible_become: "{{ g_sudo | default(omit) }}"
  130. with_items: "{{ groups.oo_masters | default([]) }}"
  131. changed_when: no
  132. - name: Evaluate oo_lb_to_config
  133. add_host:
  134. name: "{{ item }}"
  135. groups: oo_lb_to_config
  136. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  137. ansible_become: "{{ g_sudo | default(omit) }}"
  138. with_items: "{{ g_lb_hosts | default([]) }}"
  139. changed_when: no
  140. - name: Evaluate oo_nfs_to_config
  141. add_host:
  142. name: "{{ item }}"
  143. groups: oo_nfs_to_config
  144. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  145. ansible_become: "{{ g_sudo | default(omit) }}"
  146. with_items: "{{ g_nfs_hosts | default([]) }}"
  147. changed_when: no
  148. - name: Evaluate oo_glusterfs_to_config
  149. add_host:
  150. name: "{{ item }}"
  151. groups: oo_glusterfs_to_config
  152. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  153. ansible_become: "{{ g_sudo | default(omit) }}"
  154. with_items: "{{ g_glusterfs_hosts | union(g_glusterfs_registry_hosts | default([])) }}"
  155. changed_when: no
  156. - name: Evaluate oo_etcd_to_migrate
  157. add_host:
  158. name: "{{ item }}"
  159. groups: oo_etcd_to_migrate
  160. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  161. ansible_become: "{{ g_sudo | default(omit) }}"
  162. with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config | default([]) | length != 0 else (groups.oo_first_master |default([]))}}"
  163. changed_when: no