evaluate_groups.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_nfs_hosts is single host
  10. fail:
  11. msg: The nfs group must be limited to one host
  12. when: g_nfs_hosts | length > 1
  13. - name: Evaluate oo_all_hosts
  14. add_host:
  15. name: "{{ item }}"
  16. groups: oo_all_hosts
  17. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  18. ansible_become: "{{ g_sudo | default(omit) }}"
  19. with_items: "{{ g_all_hosts | default([]) }}"
  20. changed_when: no
  21. - name: Evaluate oo_masters
  22. add_host:
  23. name: "{{ item }}"
  24. groups: oo_masters
  25. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  26. ansible_become: "{{ g_sudo | default(omit) }}"
  27. with_items: "{{ g_master_hosts | union(g_new_master_hosts) | default([]) }}"
  28. changed_when: no
  29. - name: Evaluate oo_first_master
  30. add_host:
  31. name: "{{ g_master_hosts[0] }}"
  32. groups: oo_first_master
  33. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  34. ansible_become: "{{ g_sudo | default(omit) }}"
  35. when: g_master_hosts|length > 0
  36. changed_when: no
  37. - name: Evaluate oo_new_etcd_to_config
  38. add_host:
  39. name: "{{ item }}"
  40. groups: oo_new_etcd_to_config
  41. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  42. ansible_become: "{{ g_sudo | default(omit) }}"
  43. with_items: "{{ g_new_etcd_hosts | default([]) }}"
  44. changed_when: no
  45. - name: Evaluate oo_masters_to_config
  46. add_host:
  47. name: "{{ item }}"
  48. groups: oo_masters_to_config
  49. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  50. ansible_become: "{{ g_sudo | default(omit) }}"
  51. with_items: "{{ g_new_master_hosts | default(g_master_hosts | default([], true), true) }}"
  52. changed_when: no
  53. - name: Evaluate oo_etcd_to_config
  54. add_host:
  55. name: "{{ item }}"
  56. groups: oo_etcd_to_config
  57. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  58. ansible_become: "{{ g_sudo | default(omit) }}"
  59. with_items: "{{ g_etcd_hosts | default([]) }}"
  60. changed_when: no
  61. - name: Evaluate oo_first_etcd
  62. add_host:
  63. name: "{{ g_etcd_hosts[0] }}"
  64. groups: oo_first_etcd
  65. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  66. ansible_become: "{{ g_sudo | default(omit) }}"
  67. when: g_etcd_hosts|length > 0
  68. changed_when: no
  69. # We use two groups one for hosts we're upgrading which doesn't include embedded etcd
  70. # The other for backing up which includes the embedded etcd host, there's no need to
  71. # upgrade embedded etcd that just happens when the master is updated.
  72. - name: Evaluate oo_etcd_hosts_to_upgrade
  73. add_host:
  74. name: "{{ item }}"
  75. groups: oo_etcd_hosts_to_upgrade
  76. with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 else [] }}"
  77. changed_when: False
  78. - name: Evaluate oo_etcd_hosts_to_backup
  79. add_host:
  80. name: "{{ item }}"
  81. groups: oo_etcd_hosts_to_backup
  82. 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([])) }}"
  83. changed_when: False
  84. - name: Evaluate oo_nodes_to_config
  85. add_host:
  86. name: "{{ item }}"
  87. groups: oo_nodes_to_config
  88. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  89. ansible_become: "{{ g_sudo | default(omit) }}"
  90. with_items: "{{ g_new_node_hosts | default(g_node_hosts | default([], true), true) }}"
  91. changed_when: no
  92. - name: Evaluate oo_nodes_to_bootstrap
  93. add_host:
  94. name: "{{ item }}"
  95. groups: oo_nodes_to_bootstrap
  96. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  97. ansible_become: "{{ g_sudo | default(omit) }}"
  98. with_items: "{{ g_new_node_hosts | default(g_node_hosts | default([], true), true) }}"
  99. changed_when: no
  100. - name: Add masters to oo_nodes_to_bootstrap
  101. add_host:
  102. name: "{{ item }}"
  103. groups: oo_nodes_to_bootstrap
  104. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  105. ansible_become: "{{ g_sudo | default(omit) }}"
  106. with_items: "{{ g_new_master_hosts | default(g_master_hosts | default([], true), true) }}"
  107. when:
  108. # Add masters to oo_nodes_to_bootstrap when we are not scaling up.
  109. # Add new masters to oo_nodes_to_bootstrap when we are scaling up masters.
  110. - g_new_node_hosts | length == 0 or g_new_master_hosts | length > 0
  111. changed_when: no
  112. - name: Evaluate oo_lb_to_config
  113. add_host:
  114. name: "{{ item }}"
  115. groups: oo_lb_to_config
  116. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  117. ansible_become: "{{ g_sudo | default(omit) }}"
  118. with_items: "{{ g_lb_hosts | default([]) }}"
  119. changed_when: no
  120. - name: Evaluate oo_nfs_to_config
  121. add_host:
  122. name: "{{ item }}"
  123. groups: oo_nfs_to_config
  124. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  125. ansible_become: "{{ g_sudo | default(omit) }}"
  126. with_items: "{{ g_nfs_hosts | default([]) }}"
  127. changed_when: no
  128. - name: Evaluate oo_glusterfs_to_config
  129. add_host:
  130. name: "{{ item }}"
  131. groups: oo_glusterfs_to_config
  132. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  133. ansible_become: "{{ g_sudo | default(omit) }}"
  134. with_items: "{{ g_glusterfs_hosts | union(g_glusterfs_registry_hosts | default([])) }}"
  135. changed_when: no
  136. - name: Evaluate oo_etcd_to_migrate
  137. add_host:
  138. name: "{{ item }}"
  139. groups: oo_etcd_to_migrate
  140. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  141. ansible_become: "{{ g_sudo | default(omit) }}"
  142. with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config | default([]) | length != 0 else (groups.oo_first_master |default([]))}}"
  143. changed_when: no