David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 1 | --- |
| 2 | - name: Ensure Prerequisites |
| 3 | apt: |
| 4 | name: "{{ item }}" |
| 5 | state: present |
| 6 | with_items: |
| 7 | - python-ethtool=0.7* |
| 8 | |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 9 | - name: Establish Interface Lists |
| 10 | set_fact: |
| 11 | reboot_required: false |
| 12 | fabric_iface_list: [] |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 13 | fabric_iface_excluded_list: [] |
| 14 | management_iface_list: [] |
| 15 | management_iface_excluded_list: [] |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 16 | changed_when: false |
| 17 | |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 18 | - name: Explicitly Ignore External and Specified Interfaces From Fabric |
| 19 | set_fact: |
| 20 | ignore_names_combined: "{{ compute_node.interfaces.external }},{{ compute_node.fabric.ignore.names }}" |
| 21 | when: |
| 22 | - compute_node.interfaces.external |
| 23 | - compute_node.fabric.ignore.names is defined and compute_node.fabric.ignore.names != omit |
| 24 | changed_when: false |
| 25 | |
| 26 | - name: Ignore External Interface From Fabric |
| 27 | set_fact: |
| 28 | ignore_names_combined: "{{ compute_node.interfaces.external }}" |
| 29 | when: |
| 30 | - compute_node.interfaces.external |
| 31 | - compute_node.fabric.ignore.names is not defined or compute_node.fabric.ignore.names == omit |
| 32 | changed_when: false |
| 33 | |
| 34 | - name: Explicity Ingnore Specified Interfaces From Fabric |
| 35 | set_fact: |
| 36 | ignore_names_combined: "{{ compute_node.fabric.ignore.names }}" |
| 37 | when: |
| 38 | - not 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: Discovery Fabric Interfaces |
| 43 | netinfo: |
| 44 | include-names: "{{ compute_node.fabric.include.names }}" |
| 45 | include-module-types: "{{ compute_node.fabric.include.module_types }}" |
| 46 | include-bus-types: "{{ compute_node.fabric.include.bus_types }}" |
| 47 | ignore-names: "{{ ignore_names_combined | default(omit) }}" |
| 48 | ignore-module-types: "{{ compute_node.fabric.ignore.module_types }}" |
| 49 | ignore-bus-types: "{{ compute_node.fabric.ignore.bus_types }}" |
| 50 | exclude-names: "{{ compute_node.fabric.exclude.names }}" |
| 51 | exclude-module-types: "{{ compute_node.fabric.exclude.module_types }}" |
| 52 | exclude-bus-types: "{{ compute_node.fabric.exclude.bus_types }}" |
| 53 | debug: on |
| 54 | |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 55 | - name: Gather Fabric Interfaces |
| 56 | set_fact: |
| 57 | fabric_iface_list: "{{ fabric_iface_list + [item] }}" |
| 58 | with_items: |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 59 | - "{{ netinfo.included.keys() | sort }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 60 | changed_when: false |
| 61 | |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 62 | - name: Gather Excluded Fabric Interfaces |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 63 | set_fact: |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 64 | fabric_iface_excluded_list: "{{ fabric_iface_excluded_list + [item] }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 65 | with_items: |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 66 | - "{{ netinfo.excluded.keys() | sort }}" |
| 67 | changed_when: false |
| 68 | |
David K. Bainbridge | 5ec8187 | 2016-10-14 14:49:09 -0700 | [diff] [blame] | 69 | - name: Initialize Modules Ignored for Management Bond |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 70 | set_fact: |
| 71 | ignore_module_types_combined: "{{ compute_node.management.ignore.module_types }}" |
| 72 | changed_when: false |
| 73 | |
David K. Bainbridge | 5ec8187 | 2016-10-14 14:49:09 -0700 | [diff] [blame] | 74 | - name: Ignore Fabric Modules for Management Bond |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 75 | set_fact: |
| 76 | ignore_module_types_combined: "{{ compute_node.fabric.include.module_types }}" |
| 77 | when: |
| 78 | - compute_node.management.ignore.module_types is not defined or compute_node.management.ignore.module_types == omit |
| 79 | - compute_node.fabric.include.module_types is defined and compute_node.fabric.include.module_types != omit |
| 80 | changed_when: false |
| 81 | |
David K. Bainbridge | 5ec8187 | 2016-10-14 14:49:09 -0700 | [diff] [blame] | 82 | - name: Explicitly Ignore External and Specified Interfaces From Management Bond |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 83 | set_fact: |
| 84 | ignore_names_combined: "{{ compute_node.interfaces.external }},{{ compute_node.management.ignore.names }}" |
| 85 | when: |
| 86 | - compute_node.interfaces.external |
| 87 | - compute_node.management.ignore.names is defined and compute_node.management.ignore.names != omit |
| 88 | changed_when: false |
| 89 | |
David K. Bainbridge | 5ec8187 | 2016-10-14 14:49:09 -0700 | [diff] [blame] | 90 | - name: Ignore External Interface From Management Bond |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 91 | set_fact: |
| 92 | ignore_names_combined: "{{ compute_node.interfaces.external }}" |
| 93 | when: |
| 94 | - compute_node.interfaces.external |
| 95 | - compute_node.management.ignore.names is not defined or compute_node.management.ignore.names == omit |
| 96 | changed_when: false |
| 97 | |
Luca Prete | cad9509 | 2017-03-20 11:35:54 -0700 | [diff] [blame^] | 98 | - name: Explicity Ignore Specified Interfaces From Management Bond |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 99 | set_fact: |
Luca Prete | cad9509 | 2017-03-20 11:35:54 -0700 | [diff] [blame^] | 100 | ignore_names_combined: "{{ compute_node.management.ignore.names }}" |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 101 | when: |
| 102 | - not compute_node.interfaces.external |
| 103 | - compute_node.management.ignore.names is defined and compute_node.management.ignore.names != omit |
| 104 | changed_when: false |
| 105 | |
| 106 | - name: Discover Management Interfaces |
| 107 | netinfo: |
| 108 | include-names: "{{ compute_node.management.include.names }}" |
| 109 | include-module-types: "{{ compute_node.management.include.module_types }}" |
| 110 | include-bus-types: "{{ compute_node.management.include.bus_types }}" |
| 111 | ignore-names: "{{ ignore_names_combined | default(omit) }}" |
| 112 | ignore-module-types: "{{ ignore_module_types_combined | default(omit) }}" |
| 113 | ignore-bus-types: "{{ compute_node.management.ignore.bus_types }}" |
| 114 | exclude-names: "{{ compute_node.management.exclude.names }}" |
| 115 | exclude-module-types: "{{ compute_node.management.exclude.module_types }}" |
| 116 | exclude-bus-types: "{{ compute_node.management.exclude.bus_types }}" |
| 117 | debug: on |
| 118 | |
| 119 | - name: Gather Management Interfaces |
| 120 | set_fact: |
| 121 | management_iface_list: "{{ management_iface_list + [item] }}" |
| 122 | with_items: |
| 123 | - "{{ netinfo.included.keys() | sort }}" |
| 124 | changed_when: false |
| 125 | |
| 126 | - name: Gather Excluded Management Interfaces |
| 127 | set_fact: |
| 128 | management_iface_excluded_list: "{{ management_iface_excluded_list + [item] }}" |
| 129 | with_items: |
| 130 | - "{{ netinfo.excluded.keys() | sort }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 131 | changed_when: false |
| 132 | |
David K. Bainbridge | 5135c55 | 2016-09-25 18:47:43 -0700 | [diff] [blame] | 133 | #- name: Ensure Loopback |
| 134 | # netfile: |
| 135 | # src: "{{ compute_node.interfaces.file }}" |
| 136 | # state: present |
| 137 | # name: lo |
| 138 | # config: loopback |
| 139 | # auto: true |
| 140 | # description: "Loopback interface" |
| 141 | # register: net_changed |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 142 | |
David K. Bainbridge | 5135c55 | 2016-09-25 18:47:43 -0700 | [diff] [blame] | 143 | #- name: Verify Loopback Change |
| 144 | # set_fact: |
| 145 | # reboot_required: "{{ net_changed.changed }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 146 | |
| 147 | - name: Ensure Fabric |
| 148 | netfile: |
| 149 | src: "{{ compute_node.interfaces.file }}" |
| 150 | state: present |
| 151 | name: fabric |
| 152 | config: static |
| 153 | auto: true |
| 154 | address: "{{ compute_node.addresses.fabric }}" |
| 155 | bond-mode: active-backup |
| 156 | bond-miimon: 100 |
| 157 | bond-slaves: none |
| 158 | description: "Leaf - Spine bonded fabric interface" |
| 159 | register: net_changed |
| 160 | |
| 161 | - name: Verify Network Change |
| 162 | set_fact: |
David K. Bainbridge | 5135c55 | 2016-09-25 18:47:43 -0700 | [diff] [blame] | 163 | reboot_required: "{{ net_changed.changed }}" |
| 164 | # reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 165 | |
| 166 | - name: Gather Primary Fabric Interface |
| 167 | set_fact: |
| 168 | fabric_primary_iface: "{{ fabric_iface_list | sort | first }}" |
| 169 | changed_when: false |
| 170 | when: fabric_iface_list|length > 0 |
| 171 | |
| 172 | - name: Ensure Primary Fabric Interface |
| 173 | netfile: |
| 174 | src: "{{ compute_node.interfaces.file }}" |
| 175 | state: present |
| 176 | auto: true |
| 177 | name: "{{ fabric_primary_iface }}" |
| 178 | config: manual |
| 179 | bond-master: fabric |
| 180 | bond-primary: "{{ fabric_primary_iface }}" |
| 181 | description: "Primary fabric interface" |
| 182 | register: net_changed |
| 183 | when: fabric_iface_list|length > 0 |
| 184 | |
| 185 | - name: Verify Primary Fabric Interface Changed |
| 186 | set_fact: |
| 187 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 188 | |
| 189 | - name: Ensure Fabric Interfaces |
| 190 | netfile: |
| 191 | src: "{{ compute_node.interfaces.file }}" |
| 192 | state: present |
| 193 | auto: true |
| 194 | name: "{{ item }}" |
| 195 | config: manual |
| 196 | bond-master: fabric |
| 197 | description: "Fabric interface" |
| 198 | register: net_changed |
| 199 | when: fabric_iface_list|length > 1 and item != fabric_primary_iface |
| 200 | with_items: |
| 201 | - "{{ fabric_iface_list | sort }}" |
| 202 | |
| 203 | - name: Verify Fabric Interfaces Changed |
| 204 | set_fact: |
| 205 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 206 | |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 207 | - name: Mark Explicitly Excluded Fabric Interfaces as Manual |
| 208 | netfile: |
| 209 | src: "{{ compute_node.interfaces.file }}" |
| 210 | state: present |
| 211 | auto: false |
| 212 | name: "{{ item }}" |
| 213 | config: manual |
| 214 | description: "Explicitly Excluded Fabric Interface" |
| 215 | register: net_changed |
| 216 | with_items: |
| 217 | - "{{ fabric_iface_excluded_list | sort }}" |
| 218 | |
| 219 | - name: Verify Fabric Interfaces Changed |
| 220 | set_fact: |
| 221 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 222 | |
David K. Bainbridge | 5b392b8 | 2016-11-15 12:31:14 -0800 | [diff] [blame] | 223 | - name: Ensure Veth Interface |
| 224 | netfile: |
| 225 | src: "{{ compute_node.interfaces.file }}" |
| 226 | state: present |
| 227 | name: veth3 |
| 228 | config: static |
| 229 | auto: true |
| 230 | address: 0.0.0.0 |
| 231 | pre-up: |
| 232 | - /sbin/ip link add name veth3 type veth peer name veth2 |
| 233 | - /sbin/ip link set veth2 up |
| 234 | - /sbin/brctl addif mgmtbr veth2 |
| 235 | pre-down: /sbin/brctl delif mgmtbr veth2 |
| 236 | post-down: /sbin/ip link del veth2 |
| 237 | description: "Veth interfaces for VTN app" |
| 238 | register: net_changed |
| 239 | |
| 240 | - name: Verify Veth Interface Changed |
| 241 | set_fact: |
| 242 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 243 | |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 244 | - name: Ensure Management Bridge DHCP |
| 245 | netfile: |
| 246 | src: "{{ compute_node.interfaces.file }}" |
| 247 | state: present |
| 248 | name: mgmtbr |
| 249 | config: "dhcp" |
| 250 | auto: true |
David K. Bainbridge | 5b392b8 | 2016-11-15 12:31:14 -0800 | [diff] [blame] | 251 | bridge_ports: "mgmtbond veth2" |
David K. Bainbridge | 5ec8187 | 2016-10-14 14:49:09 -0700 | [diff] [blame] | 252 | description: "Internal POD management bridge" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 253 | register: net_changed |
| 254 | when: compute_node.addresses.management == "dhcp" |
| 255 | |
| 256 | - name: Verify Management Bridge DHCP Changed |
| 257 | set_fact: |
| 258 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 259 | |
| 260 | - name: Ensure Management Bridge STATIC |
| 261 | netfile: |
| 262 | src: "{{ compute_node.interfaces.file }}" |
| 263 | state: present |
| 264 | name: mgmtbr |
| 265 | config: static |
| 266 | auto: true |
| 267 | address: "{{ compute_node.addresses.management }}" |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 268 | gateway: "{{ compute_node.gateway.management }}" |
| 269 | broadcast: "{{ compute_node.broadcast.management }}" |
David K. Bainbridge | 5b392b8 | 2016-11-15 12:31:14 -0800 | [diff] [blame] | 270 | bridge_ports: "mgmtbond veth2" |
David K. Bainbridge | 5ec8187 | 2016-10-14 14:49:09 -0700 | [diff] [blame] | 271 | description: "Internal POD management bridge" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 272 | register: net_changed |
| 273 | when: compute_node.addresses.management != "dhcp" |
| 274 | |
| 275 | - name: Verify Management Bridge STATIC Changed |
| 276 | set_fact: |
| 277 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 278 | |
David K. Bainbridge | 5ec8187 | 2016-10-14 14:49:09 -0700 | [diff] [blame] | 279 | - name: Ensure Management Bond |
| 280 | netfile: |
| 281 | src: "{{ compute_node.interfaces.file }}" |
| 282 | state: present |
| 283 | name: mgmtbond |
| 284 | config: "manual" |
| 285 | auto: true |
| 286 | bond-mode: active-backup |
| 287 | bond-miimon: 100 |
| 288 | bond-slaves: none |
| 289 | description: "Internal POD management bond" |
| 290 | register: net_changed |
| 291 | |
| 292 | - name: Verify Management Bond DHCP Changed |
| 293 | set_fact: |
| 294 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 295 | |
| 296 | - name: Gather Primary Management Interface |
| 297 | set_fact: |
| 298 | management_primary_iface: "{{ management_iface_list | sort | first }}" |
| 299 | changed_when: false |
| 300 | when: management_iface_list|length > 0 |
| 301 | |
| 302 | - name: Ensure Primary Management Interface |
| 303 | netfile: |
| 304 | src: "{{ compute_node.interfaces.file }}" |
| 305 | state: present |
| 306 | auto: true |
| 307 | name: "{{ management_primary_iface }}" |
| 308 | config: manual |
| 309 | bond-master: mgmtbond |
| 310 | bond-primary: "{{ management_primary_iface }}" |
| 311 | description: "Primary management interface" |
| 312 | register: net_changed |
| 313 | when: management_iface_list|length > 0 |
| 314 | |
| 315 | - name: Verify Primary Management Interface Changed |
| 316 | set_fact: |
| 317 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 318 | |
| 319 | - name: Ensure Management Interfaces |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 320 | netfile: |
| 321 | src: "{{ compute_node.interfaces.file }}" |
| 322 | state: present |
| 323 | auto: true |
| 324 | name: "{{ item }}" |
| 325 | config: manual |
David K. Bainbridge | 5ec8187 | 2016-10-14 14:49:09 -0700 | [diff] [blame] | 326 | bond-master: mgmtbond |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 327 | description: "Management interface" |
| 328 | register: net_changed |
David K. Bainbridge | 5ec8187 | 2016-10-14 14:49:09 -0700 | [diff] [blame] | 329 | when: management_iface_list|length > 1 and item != management_primary_iface |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 330 | with_items: |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 331 | - "{{ management_iface_list | sort }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 332 | |
David K. Bainbridge | 5ec8187 | 2016-10-14 14:49:09 -0700 | [diff] [blame] | 333 | - name: Verify Management Interfaces Changed |
| 334 | set_fact: |
| 335 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 336 | |
| 337 | - name: Mark Explicitly Excluded Management Bond Interfaces as Manual |
| 338 | netfile: |
| 339 | src: "{{ compute_node.interfaces.file }}" |
| 340 | state: present |
| 341 | auto: false |
| 342 | name: "{{ item }}" |
| 343 | config: manual |
| 344 | description: "Explicitly Excluded Management Bond Interface" |
| 345 | register: net_changed |
| 346 | with_items: |
| 347 | - "{{ management_iface_excluded_list | sort }}" |
| 348 | |
| 349 | - name: Verify Explicitly Excluded Management Interfaces Changed |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 350 | set_fact: |
| 351 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 352 | |
| 353 | - name: Ensure External Interface DHCP |
| 354 | netfile: |
| 355 | src: "{{ compute_node.interfaces.file }}" |
| 356 | state: present |
| 357 | auto: true |
| 358 | name: "{{ compute_node.interfaces.external }}" |
| 359 | config: dhcp |
| 360 | description: "External interface from POD to Internet (uplink)" |
| 361 | register: net_changed |
| 362 | when: compute_node.interfaces.external and compute_node.addresses.external == "dhcp" |
| 363 | |
| 364 | - name: Verify External Interface DHCP Changed |
| 365 | set_fact: |
| 366 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 367 | |
| 368 | - name: Ensure External Interface STATIC |
| 369 | netfile: |
| 370 | src: "{{ compute_node.interfaces.file }}" |
| 371 | state: present |
| 372 | auto: true |
| 373 | name: "{{ compute_node.interfaces.external }}" |
| 374 | config: static |
| 375 | address: "{{ compute_node.addresses.external }}" |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 376 | gateway: "{{ compute_node.gateway.external }}" |
| 377 | broadcast: "{{ compute_node.broadcast.external }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 378 | description: "External interface from POD to Internet (uplink)" |
| 379 | register: net_changed |
| 380 | when: compute_node.interfaces.external and compute_node.addresses.external != "dhcp" |
| 381 | |
| 382 | - name: Verify External Interface STATIC Changed |
| 383 | set_fact: |
| 384 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 385 | |
| 386 | - name: Reboot Required |
| 387 | command: /sbin/reboot |
| 388 | async: 0 |
| 389 | poll: 0 |
| 390 | ignore_errors: true |
| 391 | when: reboot_required |
| 392 | tags: |
| 393 | - interface_config |
| 394 | - reboot |
| 395 | |
| 396 | - name: Ensure Port Defined |
| 397 | set_fact: |
| 398 | ansible_ssh_port: 22 |
| 399 | when: ansible_ssh_port is not defined |
| 400 | |
| 401 | - name: Wait For Restart |
| 402 | local_action: wait_for port={{ ansible_ssh_port }} host={{ inventory_hostname }} search_regex=OpenSSH delay=120 timeout=600 connect_timeout=15 |
| 403 | when: reboot_required |
| 404 | tags: |
| 405 | - interface_config |
| 406 | - reboot |