evaluate_groups.yml 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ---
  2. - name: Populate config host groups
  3. hosts: localhost
  4. connection: local
  5. become: no
  6. gather_facts: no
  7. tasks:
  8. - fail:
  9. msg: This playbook requires g_etcd_group to be set
  10. when: g_etcd_group is not defined
  11. - fail:
  12. msg: This playbook requires g_masters_group to be set
  13. when: g_masters_group is not defined
  14. - fail:
  15. msg: This playbook requires g_nodes_group or g_new_nodes_group to be set
  16. when: g_nodes_group is not defined and g_new_nodes_group is not defined
  17. - fail:
  18. msg: This playbook requires g_lb_group to be set
  19. when: g_lb_group is not defined
  20. - name: Evaluate oo_etcd_to_config
  21. add_host:
  22. name: "{{ item }}"
  23. groups: oo_etcd_to_config
  24. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  25. ansible_sudo: "{{ g_sudo | default(omit) }}"
  26. with_items: groups[g_etcd_group] | default([])
  27. - name: Evaluate oo_masters_to_config
  28. add_host:
  29. name: "{{ item }}"
  30. groups: oo_masters_to_config
  31. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  32. ansible_sudo: "{{ g_sudo | default(omit) }}"
  33. with_items: groups[g_masters_group] | default([])
  34. # Use g_new_nodes_group if it exists otherwise g_nodes_group
  35. - set_fact:
  36. g_nodes_to_config: "{{ g_new_nodes_group | default(g_nodes_group | default([])) }}"
  37. - name: Evaluate oo_nodes_to_config
  38. add_host:
  39. name: "{{ item }}"
  40. groups: oo_nodes_to_config
  41. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  42. ansible_sudo: "{{ g_sudo | default(omit) }}"
  43. with_items: groups[g_nodes_to_config] | default([])
  44. # Skip adding the master to oo_nodes_to_config when g_new_nodes_group is
  45. - name: Evaluate oo_nodes_to_config
  46. add_host:
  47. name: "{{ item }}"
  48. groups: oo_nodes_to_config
  49. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  50. ansible_sudo: "{{ g_sudo | default(omit) }}"
  51. with_items: groups[g_masters_group] | default([])
  52. when: g_nodeonmaster | default(false) == true and g_new_nodes_group is not defined
  53. - name: Evaluate oo_first_etcd
  54. add_host:
  55. name: "{{ groups[g_etcd_group][0] }}"
  56. groups: oo_first_etcd
  57. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  58. when: g_etcd_group in groups and (groups[g_etcd_group] | length) > 0
  59. - name: Evaluate oo_first_master
  60. add_host:
  61. name: "{{ groups[g_masters_group][0] }}"
  62. groups: oo_first_master
  63. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  64. ansible_sudo: "{{ g_sudo | default(omit) }}"
  65. when: g_masters_group in groups and (groups[g_masters_group] | length) > 0
  66. - name: Evaluate oo_lb_to_config
  67. add_host:
  68. name: "{{ item }}"
  69. groups: oo_lb_to_config
  70. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  71. ansible_sudo: "{{ g_sudo | default(omit) }}"
  72. with_items: groups[g_lb_group] | default([])