blob: 64113350cf3ec91c85e01c0491b418f6d292bea7 [file] [log] [blame]
Jonathan Hart93956f52017-08-22 13:12:42 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
David K. Bainbridgea677d4e2016-09-11 20:01:32 -070017---
18- name: Ensure Prerequisites
19 apt:
20 name: "{{ item }}"
21 state: present
22 with_items:
23 - python-ethtool=0.7*
24
David K. Bainbridgea677d4e2016-09-11 20:01:32 -070025- name: Establish Interface Lists
26 set_fact:
27 reboot_required: false
28 fabric_iface_list: []
David K. Bainbridge603ee542016-10-04 21:11:05 -070029 fabric_iface_excluded_list: []
30 management_iface_list: []
31 management_iface_excluded_list: []
David K. Bainbridgea677d4e2016-09-11 20:01:32 -070032 changed_when: false
33
David K. Bainbridge603ee542016-10-04 21:11:05 -070034- name: Explicitly Ignore External and Specified Interfaces From Fabric
35 set_fact:
36 ignore_names_combined: "{{ compute_node.interfaces.external }},{{ compute_node.fabric.ignore.names }}"
37 when:
38 - compute_node.interfaces.external
39 - compute_node.fabric.ignore.names is defined and compute_node.fabric.ignore.names != omit
40 changed_when: false
41
42- name: Ignore External Interface From Fabric
43 set_fact:
44 ignore_names_combined: "{{ compute_node.interfaces.external }}"
45 when:
46 - compute_node.interfaces.external
47 - compute_node.fabric.ignore.names is not defined or compute_node.fabric.ignore.names == omit
48 changed_when: false
49
50- name: Explicity Ingnore Specified Interfaces From Fabric
51 set_fact:
52 ignore_names_combined: "{{ compute_node.fabric.ignore.names }}"
53 when:
54 - not compute_node.interfaces.external
55 - compute_node.fabric.ignore.names is defined and compute_node.fabric.ignore.names != omit
56 changed_when: false
57
58- name: Discovery Fabric Interfaces
59 netinfo:
60 include-names: "{{ compute_node.fabric.include.names }}"
61 include-module-types: "{{ compute_node.fabric.include.module_types }}"
62 include-bus-types: "{{ compute_node.fabric.include.bus_types }}"
63 ignore-names: "{{ ignore_names_combined | default(omit) }}"
64 ignore-module-types: "{{ compute_node.fabric.ignore.module_types }}"
65 ignore-bus-types: "{{ compute_node.fabric.ignore.bus_types }}"
66 exclude-names: "{{ compute_node.fabric.exclude.names }}"
67 exclude-module-types: "{{ compute_node.fabric.exclude.module_types }}"
68 exclude-bus-types: "{{ compute_node.fabric.exclude.bus_types }}"
69 debug: on
70
David K. Bainbridgea677d4e2016-09-11 20:01:32 -070071- name: Gather Fabric Interfaces
72 set_fact:
73 fabric_iface_list: "{{ fabric_iface_list + [item] }}"
74 with_items:
David K. Bainbridge603ee542016-10-04 21:11:05 -070075 - "{{ netinfo.included.keys() | sort }}"
David K. Bainbridgea677d4e2016-09-11 20:01:32 -070076 changed_when: false
77
David K. Bainbridge603ee542016-10-04 21:11:05 -070078- name: Gather Excluded Fabric Interfaces
David K. Bainbridgea677d4e2016-09-11 20:01:32 -070079 set_fact:
David K. Bainbridge603ee542016-10-04 21:11:05 -070080 fabric_iface_excluded_list: "{{ fabric_iface_excluded_list + [item] }}"
David K. Bainbridgea677d4e2016-09-11 20:01:32 -070081 with_items:
David K. Bainbridge603ee542016-10-04 21:11:05 -070082 - "{{ netinfo.excluded.keys() | sort }}"
83 changed_when: false
84
David K. Bainbridge5ec81872016-10-14 14:49:09 -070085- name: Initialize Modules Ignored for Management Bond
David K. Bainbridge603ee542016-10-04 21:11:05 -070086 set_fact:
87 ignore_module_types_combined: "{{ compute_node.management.ignore.module_types }}"
88 changed_when: false
89
David K. Bainbridge5ec81872016-10-14 14:49:09 -070090- name: Ignore Fabric Modules for Management Bond
David K. Bainbridge603ee542016-10-04 21:11:05 -070091 set_fact:
92 ignore_module_types_combined: "{{ compute_node.fabric.include.module_types }}"
93 when:
94 - compute_node.management.ignore.module_types is not defined or compute_node.management.ignore.module_types == omit
95 - compute_node.fabric.include.module_types is defined and compute_node.fabric.include.module_types != omit
96 changed_when: false
97
David K. Bainbridge5ec81872016-10-14 14:49:09 -070098- name: Explicitly Ignore External and Specified Interfaces From Management Bond
David K. Bainbridge603ee542016-10-04 21:11:05 -070099 set_fact:
100 ignore_names_combined: "{{ compute_node.interfaces.external }},{{ compute_node.management.ignore.names }}"
101 when:
102 - compute_node.interfaces.external
103 - compute_node.management.ignore.names is defined and compute_node.management.ignore.names != omit
104 changed_when: false
105
David K. Bainbridge5ec81872016-10-14 14:49:09 -0700106- name: Ignore External Interface From Management Bond
David K. Bainbridge603ee542016-10-04 21:11:05 -0700107 set_fact:
108 ignore_names_combined: "{{ compute_node.interfaces.external }}"
109 when:
110 - compute_node.interfaces.external
111 - compute_node.management.ignore.names is not defined or compute_node.management.ignore.names == omit
112 changed_when: false
113
Luca Pretea78efbe2017-03-20 11:26:09 -0700114- name: Explicity Ignore Specified Interfaces From Management Bond
David K. Bainbridge603ee542016-10-04 21:11:05 -0700115 set_fact:
Luca Pretea78efbe2017-03-20 11:26:09 -0700116 ignore_names_combined: "{{ compute_node.management.ignore.names }}"
David K. Bainbridge603ee542016-10-04 21:11:05 -0700117 when:
118 - not compute_node.interfaces.external
119 - compute_node.management.ignore.names is defined and compute_node.management.ignore.names != omit
120 changed_when: false
121
122- name: Discover Management Interfaces
123 netinfo:
124 include-names: "{{ compute_node.management.include.names }}"
125 include-module-types: "{{ compute_node.management.include.module_types }}"
126 include-bus-types: "{{ compute_node.management.include.bus_types }}"
127 ignore-names: "{{ ignore_names_combined | default(omit) }}"
128 ignore-module-types: "{{ ignore_module_types_combined | default(omit) }}"
129 ignore-bus-types: "{{ compute_node.management.ignore.bus_types }}"
130 exclude-names: "{{ compute_node.management.exclude.names }}"
131 exclude-module-types: "{{ compute_node.management.exclude.module_types }}"
132 exclude-bus-types: "{{ compute_node.management.exclude.bus_types }}"
133 debug: on
134
135- name: Gather Management Interfaces
136 set_fact:
137 management_iface_list: "{{ management_iface_list + [item] }}"
138 with_items:
139 - "{{ netinfo.included.keys() | sort }}"
140 changed_when: false
141
142- name: Gather Excluded Management Interfaces
143 set_fact:
144 management_iface_excluded_list: "{{ management_iface_excluded_list + [item] }}"
145 with_items:
146 - "{{ netinfo.excluded.keys() | sort }}"
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700147 changed_when: false
148
David K. Bainbridge5135c552016-09-25 18:47:43 -0700149#- name: Ensure Loopback
150# netfile:
151# src: "{{ compute_node.interfaces.file }}"
152# state: present
153# name: lo
154# config: loopback
155# auto: true
156# description: "Loopback interface"
157# register: net_changed
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700158
David K. Bainbridge5135c552016-09-25 18:47:43 -0700159#- name: Verify Loopback Change
160# set_fact:
161# reboot_required: "{{ net_changed.changed }}"
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700162
163- name: Ensure Fabric
164 netfile:
165 src: "{{ compute_node.interfaces.file }}"
166 state: present
167 name: fabric
168 config: static
169 auto: true
170 address: "{{ compute_node.addresses.fabric }}"
171 bond-mode: active-backup
172 bond-miimon: 100
173 bond-slaves: none
174 description: "Leaf - Spine bonded fabric interface"
175 register: net_changed
176
177- name: Verify Network Change
178 set_fact:
David K. Bainbridge5135c552016-09-25 18:47:43 -0700179 reboot_required: "{{ net_changed.changed }}"
180# reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700181
182- name: Gather Primary Fabric Interface
183 set_fact:
184 fabric_primary_iface: "{{ fabric_iface_list | sort | first }}"
185 changed_when: false
186 when: fabric_iface_list|length > 0
187
188- name: Ensure Primary Fabric Interface
189 netfile:
190 src: "{{ compute_node.interfaces.file }}"
191 state: present
192 auto: true
193 name: "{{ fabric_primary_iface }}"
194 config: manual
195 bond-master: fabric
196 bond-primary: "{{ fabric_primary_iface }}"
197 description: "Primary fabric interface"
198 register: net_changed
199 when: fabric_iface_list|length > 0
200
201- name: Verify Primary Fabric Interface Changed
202 set_fact:
203 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
204
205- name: Ensure Fabric Interfaces
206 netfile:
207 src: "{{ compute_node.interfaces.file }}"
208 state: present
209 auto: true
210 name: "{{ item }}"
211 config: manual
212 bond-master: fabric
213 description: "Fabric interface"
214 register: net_changed
215 when: fabric_iface_list|length > 1 and item != fabric_primary_iface
216 with_items:
217 - "{{ fabric_iface_list | sort }}"
218
219- name: Verify Fabric Interfaces Changed
220 set_fact:
221 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
222
David K. Bainbridge603ee542016-10-04 21:11:05 -0700223- name: Mark Explicitly Excluded Fabric Interfaces as Manual
224 netfile:
225 src: "{{ compute_node.interfaces.file }}"
226 state: present
227 auto: false
228 name: "{{ item }}"
229 config: manual
230 description: "Explicitly Excluded Fabric Interface"
231 register: net_changed
232 with_items:
233 - "{{ fabric_iface_excluded_list | sort }}"
234
235- name: Verify Fabric Interfaces Changed
236 set_fact:
237 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
238
David K. Bainbridge5b392b82016-11-15 12:31:14 -0800239- name: Ensure Veth Interface
240 netfile:
241 src: "{{ compute_node.interfaces.file }}"
242 state: present
243 name: veth3
244 config: static
245 auto: true
246 address: 0.0.0.0
247 pre-up:
248 - /sbin/ip link add name veth3 type veth peer name veth2
249 - /sbin/ip link set veth2 up
250 - /sbin/brctl addif mgmtbr veth2
251 pre-down: /sbin/brctl delif mgmtbr veth2
252 post-down: /sbin/ip link del veth2
253 description: "Veth interfaces for VTN app"
254 register: net_changed
255
256- name: Verify Veth Interface Changed
257 set_fact:
258 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
259
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700260- name: Ensure Management Bridge DHCP
261 netfile:
262 src: "{{ compute_node.interfaces.file }}"
263 state: present
264 name: mgmtbr
265 config: "dhcp"
266 auto: true
David K. Bainbridge5b392b82016-11-15 12:31:14 -0800267 bridge_ports: "mgmtbond veth2"
David K. Bainbridge5ec81872016-10-14 14:49:09 -0700268 description: "Internal POD management bridge"
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700269 register: net_changed
270 when: compute_node.addresses.management == "dhcp"
271
272- name: Verify Management Bridge DHCP Changed
273 set_fact:
274 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
275
276- name: Ensure Management Bridge STATIC
277 netfile:
278 src: "{{ compute_node.interfaces.file }}"
279 state: present
280 name: mgmtbr
281 config: static
282 auto: true
283 address: "{{ compute_node.addresses.management }}"
David K. Bainbridge603ee542016-10-04 21:11:05 -0700284 gateway: "{{ compute_node.gateway.management }}"
285 broadcast: "{{ compute_node.broadcast.management }}"
David K. Bainbridge5b392b82016-11-15 12:31:14 -0800286 bridge_ports: "mgmtbond veth2"
David K. Bainbridge5ec81872016-10-14 14:49:09 -0700287 description: "Internal POD management bridge"
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700288 register: net_changed
289 when: compute_node.addresses.management != "dhcp"
290
291- name: Verify Management Bridge STATIC Changed
292 set_fact:
293 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
294
David K. Bainbridge5ec81872016-10-14 14:49:09 -0700295- name: Ensure Management Bond
296 netfile:
297 src: "{{ compute_node.interfaces.file }}"
298 state: present
299 name: mgmtbond
300 config: "manual"
301 auto: true
302 bond-mode: active-backup
303 bond-miimon: 100
304 bond-slaves: none
305 description: "Internal POD management bond"
306 register: net_changed
307
308- name: Verify Management Bond DHCP Changed
309 set_fact:
310 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
311
312- name: Gather Primary Management Interface
313 set_fact:
314 management_primary_iface: "{{ management_iface_list | sort | first }}"
315 changed_when: false
316 when: management_iface_list|length > 0
317
318- name: Ensure Primary Management Interface
319 netfile:
320 src: "{{ compute_node.interfaces.file }}"
321 state: present
322 auto: true
323 name: "{{ management_primary_iface }}"
324 config: manual
325 bond-master: mgmtbond
326 bond-primary: "{{ management_primary_iface }}"
327 description: "Primary management interface"
328 register: net_changed
329 when: management_iface_list|length > 0
330
331- name: Verify Primary Management Interface Changed
332 set_fact:
333 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
334
335- name: Ensure Management Interfaces
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700336 netfile:
337 src: "{{ compute_node.interfaces.file }}"
338 state: present
339 auto: true
340 name: "{{ item }}"
341 config: manual
David K. Bainbridge5ec81872016-10-14 14:49:09 -0700342 bond-master: mgmtbond
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700343 description: "Management interface"
344 register: net_changed
David K. Bainbridge5ec81872016-10-14 14:49:09 -0700345 when: management_iface_list|length > 1 and item != management_primary_iface
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700346 with_items:
David K. Bainbridge603ee542016-10-04 21:11:05 -0700347 - "{{ management_iface_list | sort }}"
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700348
David K. Bainbridge5ec81872016-10-14 14:49:09 -0700349- name: Verify Management Interfaces Changed
350 set_fact:
351 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
352
353- name: Mark Explicitly Excluded Management Bond Interfaces as Manual
354 netfile:
355 src: "{{ compute_node.interfaces.file }}"
356 state: present
357 auto: false
358 name: "{{ item }}"
359 config: manual
360 description: "Explicitly Excluded Management Bond Interface"
361 register: net_changed
362 with_items:
363 - "{{ management_iface_excluded_list | sort }}"
364
365- name: Verify Explicitly Excluded Management Interfaces Changed
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700366 set_fact:
367 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
368
369- name: Ensure External Interface DHCP
370 netfile:
371 src: "{{ compute_node.interfaces.file }}"
372 state: present
373 auto: true
374 name: "{{ compute_node.interfaces.external }}"
375 config: dhcp
376 description: "External interface from POD to Internet (uplink)"
377 register: net_changed
378 when: compute_node.interfaces.external and compute_node.addresses.external == "dhcp"
379
380- name: Verify External Interface DHCP Changed
381 set_fact:
382 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
383
384- name: Ensure External Interface STATIC
385 netfile:
386 src: "{{ compute_node.interfaces.file }}"
387 state: present
388 auto: true
389 name: "{{ compute_node.interfaces.external }}"
390 config: static
391 address: "{{ compute_node.addresses.external }}"
David K. Bainbridge603ee542016-10-04 21:11:05 -0700392 gateway: "{{ compute_node.gateway.external }}"
393 broadcast: "{{ compute_node.broadcast.external }}"
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700394 description: "External interface from POD to Internet (uplink)"
395 register: net_changed
396 when: compute_node.interfaces.external and compute_node.addresses.external != "dhcp"
397
398- name: Verify External Interface STATIC Changed
399 set_fact:
400 reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}"
401
402- name: Reboot Required
403 command: /sbin/reboot
404 async: 0
405 poll: 0
406 ignore_errors: true
407 when: reboot_required
408 tags:
409 - interface_config
410 - reboot
411
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700412- name: Wait For Restart
gopinathe2d8db42017-08-29 17:59:19 -0700413 local_action: wait_for port={{ ansible_port | default('22') }} host={{ inventory_hostname }} search_regex=OpenSSH delay=120 timeout=600 connect_timeout=15
David K. Bainbridgea677d4e2016-09-11 20:01:32 -0700414 when: reboot_required
415 tags:
416 - interface_config
gopinathe2d8db42017-08-29 17:59:19 -0700417 - reboot