evaluate_groups.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_hosts to be set
  10. when: g_etcd_hosts is not defined
  11. - fail:
  12. msg: This playbook requires g_master_hosts or g_new_master_hosts to be set
  13. when: g_master_hosts is not defined and g_new_master_hosts is not defined
  14. - fail:
  15. msg: This playbook requires g_node_hosts or g_new_node_hosts to be set
  16. when: g_node_hosts is not defined and g_new_node_hosts is not defined
  17. - fail:
  18. msg: This playbook requires g_lb_hosts to be set
  19. when: g_lb_hosts is not defined
  20. - fail:
  21. msg: This playbook requires g_nfs_hosts to be set
  22. when: g_nfs_hosts is not defined
  23. - fail:
  24. msg: The nfs group must be limited to one host
  25. when: (groups[g_nfs_hosts] | default([])) | length > 1
  26. - name: Evaluate oo_all_hosts
  27. add_host:
  28. name: "{{ item }}"
  29. groups: oo_all_hosts
  30. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  31. ansible_become: "{{ g_sudo | default(omit) }}"
  32. with_items: "{{ g_all_hosts | default([]) }}"
  33. - name: Evaluate oo_masters
  34. add_host:
  35. name: "{{ item }}"
  36. groups: oo_masters
  37. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  38. ansible_become: "{{ g_sudo | default(omit) }}"
  39. with_items: "{{ g_master_hosts | union(g_new_master_hosts) | default([]) }}"
  40. - name: Evaluate oo_etcd_to_config
  41. add_host:
  42. name: "{{ item }}"
  43. groups: oo_etcd_to_config
  44. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  45. ansible_become: "{{ g_sudo | default(omit) }}"
  46. with_items: "{{ g_etcd_hosts | default([]) }}"
  47. - name: Evaluate oo_masters_to_config
  48. add_host:
  49. name: "{{ item }}"
  50. groups: oo_masters_to_config
  51. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  52. ansible_become: "{{ g_sudo | default(omit) }}"
  53. with_items: "{{ g_new_master_hosts | default(g_master_hosts | default([], true), true) }}"
  54. - name: Evaluate oo_nodes_to_config
  55. add_host:
  56. name: "{{ item }}"
  57. groups: oo_nodes_to_config
  58. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  59. ansible_become: "{{ g_sudo | default(omit) }}"
  60. with_items: "{{ g_new_node_hosts | default(g_node_hosts | default([], true), true) }}"
  61. # Skip adding the master to oo_nodes_to_config when g_new_node_hosts is
  62. - name: Evaluate oo_nodes_to_config
  63. add_host:
  64. name: "{{ item }}"
  65. groups: oo_nodes_to_config
  66. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  67. ansible_become: "{{ g_sudo | default(omit) }}"
  68. with_items: "{{ g_master_hosts | default([]) }}"
  69. when: g_nodeonmaster | default(false) == true and g_new_node_hosts is not defined
  70. - name: Evaluate oo_first_etcd
  71. add_host:
  72. name: "{{ g_etcd_hosts[0] }}"
  73. groups: oo_first_etcd
  74. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  75. when: g_etcd_hosts|length > 0
  76. - name: Evaluate oo_first_master
  77. add_host:
  78. name: "{{ g_master_hosts[0] }}"
  79. groups: oo_first_master
  80. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  81. ansible_become: "{{ g_sudo | default(omit) }}"
  82. when: g_master_hosts|length > 0
  83. - name: Evaluate oo_lb_to_config
  84. add_host:
  85. name: "{{ item }}"
  86. groups: oo_lb_to_config
  87. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  88. ansible_become: "{{ g_sudo | default(omit) }}"
  89. with_items: "{{ g_lb_hosts | default([]) }}"
  90. - name: Evaluate oo_nfs_to_config
  91. add_host:
  92. name: "{{ item }}"
  93. groups: oo_nfs_to_config
  94. ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
  95. ansible_become: "{{ g_sudo | default(omit) }}"
  96. with_items: "{{ g_nfs_hosts | default([]) }}"