summaryrefslogtreecommitdiffstats
path: root/playbooks/init/evaluate_groups.yml
blob: e8bf1892c1e288ab65182da47c22a2c6b8ae4071 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---
- name: Populate config host groups
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
  - name: Load group name mapping variables
    include_vars: vars/cluster_hosts.yml

  - name: Evaluate groups - g_etcd_hosts or g_new_etcd_hosts required
    fail:
      msg: This playbook requires g_etcd_hosts or g_new_etcd_hosts to be set
    when: g_etcd_hosts is not defined and g_new_etcd_hosts is not defined

  - name: Evaluate groups - g_master_hosts or g_new_master_hosts required
    fail:
      msg: This playbook requires g_master_hosts or g_new_master_hosts to be set
    when: g_master_hosts is not defined and g_new_master_hosts is not defined

  - name: Evaluate groups - g_node_hosts or g_new_node_hosts required
    fail:
      msg: This playbook requires g_node_hosts or g_new_node_hosts to be set
    when: g_node_hosts is not defined and g_new_node_hosts is not defined

  - name: Evaluate groups - g_lb_hosts required
    fail:
      msg: This playbook requires g_lb_hosts to be set
    when: g_lb_hosts is not defined

  - name: Evaluate groups - g_nfs_hosts required
    fail:
      msg: This playbook requires g_nfs_hosts to be set
    when: g_nfs_hosts is not defined

  - name: Evaluate groups - g_nfs_hosts is single host
    fail:
      msg: The nfs group must be limited to one host
    when: g_nfs_hosts | default([]) | length > 1

  - name: Evaluate groups - g_glusterfs_hosts required
    fail:
      msg: This playbook requires g_glusterfs_hosts to be set
    when: g_glusterfs_hosts is not defined

  - name: Evaluate groups - Fail if no etcd hosts group is defined
    fail:
      msg: >
        Running etcd as an embedded service is no longer supported. If this is a
        new install please define an 'etcd' group with either one, three or five
        hosts. These hosts may be the same hosts as your masters. If this is an
        upgrade please see https://docs.openshift.com/container-platform/latest/install_config/upgrading/migrating_embedded_etcd.html
        for documentation on how to migrate from embedded to external etcd.
    when:
    - g_etcd_hosts | default([]) | length not in [5,3,1]
    - not (openshift_node_bootstrap | default(False))

  - name: Evaluate oo_all_hosts
    add_host:
      name: "{{ item }}"
      groups: oo_all_hosts
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ g_all_hosts | default([]) }}"
    changed_when: no

  - name: Evaluate oo_masters
    add_host:
      name: "{{ item }}"
      groups: oo_masters
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ g_master_hosts | union(g_new_master_hosts) | default([]) }}"
    changed_when: no

  - name: Evaluate oo_first_master
    add_host:
      name: "{{ g_master_hosts[0] }}"
      groups: oo_first_master
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    when: g_master_hosts|length > 0
    changed_when: no

  - name: Evaluate oo_new_etcd_to_config
    add_host:
      name: "{{ item }}"
      groups: oo_new_etcd_to_config
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ g_new_etcd_hosts | default([]) }}"
    changed_when: no

  - name: Evaluate oo_masters_to_config
    add_host:
      name: "{{ item }}"
      groups: oo_masters_to_config
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ g_new_master_hosts | default(g_master_hosts | default([], true), true) }}"
    changed_when: no

  - name: Evaluate oo_etcd_to_config
    add_host:
      name: "{{ item }}"
      groups: oo_etcd_to_config
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ g_etcd_hosts | default([]) }}"
    changed_when: no

  - name: Evaluate oo_first_etcd
    add_host:
      name: "{{ g_etcd_hosts[0] }}"
      groups: oo_first_etcd
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    when: g_etcd_hosts|length > 0
    changed_when: no

  # We use two groups one for hosts we're upgrading which doesn't include embedded etcd
  # The other for backing up which includes the embedded etcd host, there's no need to
  # upgrade embedded etcd that just happens when the master is updated.
  - name: Evaluate oo_etcd_hosts_to_upgrade
    add_host:
      name: "{{ item }}"
      groups: oo_etcd_hosts_to_upgrade
    with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config is defined and groups.oo_etcd_to_config | length > 0 else [] }}"
    changed_when: False

  - name: Evaluate oo_etcd_hosts_to_backup
    add_host:
      name: "{{ item }}"
      groups: oo_etcd_hosts_to_backup
    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([])) }}"
    changed_when: False

  - name: Evaluate oo_nodes_to_config
    add_host:
      name: "{{ item }}"
      groups: oo_nodes_to_config
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ g_new_node_hosts | default(g_node_hosts | default([], true), true) }}"
    changed_when: no

  # Skip adding the master to oo_nodes_to_config when g_new_node_hosts is
  - name: Add master to oo_nodes_to_config
    add_host:
      name: "{{ item }}"
      groups: oo_nodes_to_config
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ g_master_hosts | default([]) }}"
    when: g_nodeonmaster | default(false) | bool and not g_new_node_hosts | default(false) | bool
    changed_when: no

  - name: Evaluate oo_lb_to_config
    add_host:
      name: "{{ item }}"
      groups: oo_lb_to_config
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ g_lb_hosts | default([]) }}"
    changed_when: no

  - name: Evaluate oo_nfs_to_config
    add_host:
      name: "{{ item }}"
      groups: oo_nfs_to_config
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ g_nfs_hosts | default([]) }}"
    changed_when: no

  - name: Evaluate oo_glusterfs_to_config
    add_host:
      name: "{{ item }}"
      groups: oo_glusterfs_to_config
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ g_glusterfs_hosts | union(g_glusterfs_registry_hosts | default([])) }}"
    changed_when: no

  - name: Evaluate oo_etcd_to_migrate
    add_host:
      name: "{{ item }}"
      groups: oo_etcd_to_migrate
      ansible_ssh_user: "{{ g_ssh_user | default(omit) }}"
      ansible_become: "{{ g_sudo | default(omit) }}"
    with_items: "{{ groups.oo_etcd_to_config if groups.oo_etcd_to_config | default([]) | length != 0 else (groups.oo_first_master |default([]))}}"
    changed_when: no