|
133 | 133 | # few tasks
|
134 | 134 | - set_fact:
|
135 | 135 | node_role_list: []
|
136 |
| - nic_list: "{{(external_uuid is defined) | ternary([{'net-id': internal_uuid}, {'net-id': external_uuid}], [{'net-id': internal_uuid}])}}" |
| 136 | + nic_list: "{{ (internal_uuid != external_uuid) | ternary([{ 'net-id': internal_uuid }, { 'net-id': external_uuid }], [{ 'net-id': external_uuid }]) }}" |
137 | 137 | - name: Build up a list of roles (per node being created)
|
138 |
| - include: build-role-list.yml static=no |
| 138 | + include_tasks: build-role-list.yml |
139 | 139 | with_items: "{{node_map | selectattr('application', 'equalto', application) | list}}"
|
140 | 140 | loop_control:
|
141 | 141 | loop_var: node_map_entry
|
|
149 | 149 | display_name: "{{project}}_{{application}}_{{node_role_list[item | int]}}_{{cluster | default('a')}}_{{item}}"
|
150 | 150 | with_sequence: start=0 end="{{(node_role_list | length) - 1}}"
|
151 | 151 | when: data_volume is defined
|
152 |
| -# openstack instance names must be unique, so we need to add a sequence number to each name |
153 |
| -- name: Launch instances |
154 |
| - os_server: |
155 |
| - state: present |
156 |
| - cloud: "{{tenant}}" |
157 |
| - name: "{{cloud}}_{{tenant}}_{{project}}_{{dataflow | default('none')}}_{{application}}_{{domain}}_{{cluster | default('a')}}_{{item}}" |
158 |
| - meta: |
159 |
| - Name: "{{cloud}}_{{tenant}}_{{project}}_{{dataflow | default('none')}}_{{application}}_{{domain}}_{{cluster | default('a')}}" |
160 |
| - Tenant: "{{tenant}}" |
161 |
| - Project: "{{project}}" |
162 |
| - Cloud: "{{cloud}}" |
163 |
| - Domain: "{{domain}}" |
164 |
| - Application: "{{application}}" |
165 |
| - Cluster: "{{cluster | default('a')}}" |
166 |
| - Role: "{{node_role_list[item | int]}}" |
167 |
| - Dataflow: "{{dataflow | default('none')}}" |
168 |
| - region_name: "{{region}}" |
169 |
| - availability_zone: "{{zone}}" |
170 |
| - image: "{{image}}" |
171 |
| - key_name: "{{keypair.key.name}}" |
172 |
| - timeout: 200 |
173 |
| - auto_ip: yes |
174 |
| - reuse_ips: true |
175 |
| - flavor: "{{type}}" |
176 |
| - nics: "{{nic_list}}" |
177 |
| - security_groups: "{{sg_names_str}}" |
178 |
| - volumes: "{{project}}_{{application}}_{{node_role_list[item | int]}}_{{cluster | default('a')}}_{{item}}" |
179 |
| - register: osp_out |
180 |
| - with_sequence: start=0 end="{{(node_role_list | length) - 1}}" |
181 |
| -# setup a floating IP address for each instance from the float_pool |
182 |
| -- name: assigning floating IPs to instances |
183 |
| - os_floating_ip: |
184 |
| - state: present |
185 |
| - reuse: true |
186 |
| - cloud: "{{tenant}}" |
187 |
| - server: "{{item.server.id}}" |
188 |
| - fixed_address: "{{item.server.addresses.public.0['addr']}}" |
189 |
| - network: "{{float_pool}}" |
190 |
| - nat_destination: "{{external_uuid}}" |
191 |
| - with_items: "{{osp_out.results}}" |
192 |
| - register: |
193 |
| - when: not osp_out | skipped and osp_out.changed and osp_out.results | length > 0 |
194 |
| -# construct the `app_group_name_list` and `node_list_name_list` lists from the |
195 |
| -# `application_roles` list |
| 152 | + |
| 153 | +# construct the `app_group_name_list` and `node_list_name_list` lists from the `application_roles` list |
196 | 154 | - set_fact:
|
197 | 155 | node_list_name_list: "{{(node_list_name_list | default([])) + [((item == 'none') | ternary((application + '_nodes'), (application + '_' + item + '_nodes')))]}}"
|
198 | 156 | app_group_name_list: "{{(app_group_name_list | default([])) + [((item == 'none') | ternary(application, application + '_' + item))]}}"
|
199 | 157 | with_items: "{{node_role_list}}"
|
200 |
| -# add the instances created to the corresponding application host group |
201 |
| -- name: Add new instances to the appropriate host groups |
202 |
| - add_host: |
203 |
| - name: "{{item.1.server.addresses.private.0['addr']}}" |
204 |
| - groups: "{{app_group_name_list[item.0 | int]}},{{node_list_name_list[item.0 | int]}}" |
205 |
| - ansible_ssh_host: "{{item.1.server.addresses.private.0['addr']}}" |
206 |
| - ansible_ssh_private_key_file: "{{private_keyfile_path}}" |
207 |
| - with_indexed_items: "{{osp_out.results}}" |
| 158 | + |
| 159 | +# this handles single subnet, eg, when internal and external uuids are identical |
| 160 | +# openstack instance names must be unique, so we need to add a sequence number to each name |
| 161 | +- block: |
| 162 | + - name: Launch single subnet instances |
| 163 | + os_server: |
| 164 | + state: present |
| 165 | + cloud: "{{tenant}}" |
| 166 | + name: "{{cloud}}_{{tenant}}_{{project}}_{{dataflow | default('none')}}_{{application}}_{{domain}}_{{cluster | default('a')}}_{{item}}" |
| 167 | + meta: |
| 168 | + Name: "{{cloud}}_{{tenant}}_{{project}}_{{dataflow | default('none')}}_{{application}}_{{domain}}_{{cluster | default('a')}}" |
| 169 | + Tenant: "{{tenant}}" |
| 170 | + Project: "{{project}}" |
| 171 | + Cloud: "{{cloud}}" |
| 172 | + Domain: "{{domain}}" |
| 173 | + Application: "{{application}}" |
| 174 | + Cluster: "{{cluster | default('a')}}" |
| 175 | + Role: "{{node_role_list[item | int]}}" |
| 176 | + Dataflow: "{{dataflow | default('none')}}" |
| 177 | + region_name: "{{region}}" |
| 178 | + availability_zone: "{{zone}}" |
| 179 | + image: "{{image}}" |
| 180 | + key_name: "{{keypair.key.name}}" |
| 181 | + timeout: 200 |
| 182 | + floating_ip_pools: "{{ float_pool }}" |
| 183 | + reuse_ips: true |
| 184 | + flavor: "{{type}}" |
| 185 | + nics: "{{nic_list}}" |
| 186 | + security_groups: "{{sg_names_str}}" |
| 187 | + volumes: "{{project}}_{{application}}_{{node_role_list[item | int]}}_{{cluster | default('a')}}_{{item}}" |
| 188 | + register: osp_single |
| 189 | + with_sequence: start=0 end="{{(node_role_list | length) - 1}}" |
| 190 | + |
| 191 | + - name: Add new instances to the appropriate host groups |
| 192 | + add_host: |
| 193 | + name: "{{item[1].server.addresses.private.0['addr']}}" |
| 194 | + groups: "{{app_group_name_list[item.0 | int]}},{{node_list_name_list[item.0 | int]}}" |
| 195 | + ansible_host: "{{item[1].server.addresses.private.1['addr']}}" |
| 196 | + ansible_ssh_private_key_file: "{{private_keyfile_path}}" |
| 197 | + with_indexed_items: "{{osp_single.results}}" |
| 198 | + when: |
| 199 | + - internal_uuid == external_uuid |
| 200 | + |
| 201 | +# this handles multiple subnets |
| 202 | +# openstack instance names must be unique, so we need to add a sequence number to each name |
| 203 | +- block: |
| 204 | + - name: Launch multiple subnet instances |
| 205 | + os_server: |
| 206 | + state: present |
| 207 | + cloud: "{{tenant}}" |
| 208 | + name: "{{cloud}}_{{tenant}}_{{project}}_{{dataflow | default('none')}}_{{application}}_{{domain}}_{{cluster | default('a')}}_{{item}}" |
| 209 | + meta: |
| 210 | + Name: "{{cloud}}_{{tenant}}_{{project}}_{{dataflow | default('none')}}_{{application}}_{{domain}}_{{cluster | default('a')}}" |
| 211 | + Tenant: "{{tenant}}" |
| 212 | + Project: "{{project}}" |
| 213 | + Cloud: "{{cloud}}" |
| 214 | + Domain: "{{domain}}" |
| 215 | + Application: "{{application}}" |
| 216 | + Cluster: "{{cluster | default('a')}}" |
| 217 | + Role: "{{node_role_list[item | int]}}" |
| 218 | + Dataflow: "{{dataflow | default('none')}}" |
| 219 | + region_name: "{{region}}" |
| 220 | + availability_zone: "{{zone}}" |
| 221 | + image: "{{image}}" |
| 222 | + key_name: "{{keypair.key.name}}" |
| 223 | + timeout: 200 |
| 224 | + auto_ip: yes |
| 225 | + reuse_ips: true |
| 226 | + flavor: "{{type}}" |
| 227 | + nics: "{{nic_list}}" |
| 228 | + security_groups: "{{sg_names_str}}" |
| 229 | + volumes: "{{project}}_{{application}}_{{node_role_list[item | int]}}_{{cluster | default('a')}}_{{item}}" |
| 230 | + register: osp_multiple |
| 231 | + with_sequence: start=0 end="{{(node_role_list | length) - 1}}" |
| 232 | + # setup a floating IP address for each instance from the float_pool |
| 233 | + - name: assigning floating IPs to instances |
| 234 | + os_floating_ip: |
| 235 | + state: present |
| 236 | + reuse: true |
| 237 | + cloud: "{{tenant}}" |
| 238 | + server: "{{item.server.id}}" |
| 239 | + fixed_address: "{{item.server.addresses.public.0['addr']}}" |
| 240 | + network: "{{float_pool}}" |
| 241 | + nat_destination: "{{external_uuid}}" |
| 242 | + with_items: "{{osp_multiple.results}}" |
| 243 | + register: |
| 244 | + when: not osp_multiple | skipped and osp_multiple.changed and osp_multiple.results | length > 0 |
| 245 | + |
| 246 | + # add the instances created to the corresponding application host group |
| 247 | + - name: Add new instances to the appropriate host groups |
| 248 | + add_host: |
| 249 | + name: "{{item.1.server.addresses.private.0['addr']}}" |
| 250 | + groups: "{{app_group_name_list[item.0 | int]}},{{node_list_name_list[item.0 | int]}}" |
| 251 | + ansible_host: "{{item.1.server.addresses.private.0['addr']}}" |
| 252 | + ansible_ssh_private_key_file: "{{private_keyfile_path}}" |
| 253 | + with_indexed_items: "{{osp_multiple.results}}" |
| 254 | + when: |
| 255 | + - internal_uuid != external_uuid |
| 256 | + |
| 257 | +# sigh @ ansible for making me do this |
| 258 | +- set_fact: |
| 259 | + osp: "{{ (internal_uuid == external_uuid) | ternary(osp_single, osp_multiple) }}" |
| 260 | + |
208 | 261 | # wait_for doesn't work with a proxy, so we need to ssh and check output
|
209 | 262 | - name: Wait for instances to be accessible via SSH
|
210 |
| - shell: /bin/sleep 10 && /usr/bin/ssh -i "{{private_keyfile_path}}" "{{user}}@{{item.server.addresses.private.0['addr']}}" echo DataNexus |
| 263 | + shell: /bin/sleep 20 && /usr/bin/ssh -i "{{ private_keyfile_path }}" "{{ user }}@{{ hostvars[item.server.addresses.private.0['addr']].ansible_host }}" echo DataNexus |
211 | 264 | register: output
|
212 |
| - retries: 24 |
213 |
| - delay: 15 |
| 265 | + retries: 4 |
| 266 | + delay: 10 |
214 | 267 | until: output.stdout.find('DataNexus') != -1
|
215 |
| - with_items: "{{osp_out.results}}" |
216 |
| - when: not osp_out | skipped and osp_out.changed and osp_out.results | length > 0 |
| 268 | + with_items: "{{osp.results}}" |
| 269 | + when: not osp | skipped and osp.changed and osp.results | length > 0 |
0 commit comments