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 | |
| 69 | - name: Initialize Modules Ignored for Management Bridge |
| 70 | set_fact: |
| 71 | ignore_module_types_combined: "{{ compute_node.management.ignore.module_types }}" |
| 72 | changed_when: false |
| 73 | |
| 74 | - name: Ignore Fabric Modules for Management Bridge |
| 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 | |
| 82 | - name: Explicitly Ignore External and Specified Interfaces From Management Bridge |
| 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 | |
| 90 | - name: Ignore External Interface From Management Bridge |
| 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 | |
| 98 | - name: Explicity Ingnore Specified Interfaces From Management Bridge |
| 99 | set_fact: |
| 100 | exclude_names_combined: "{{ compute_node.management.ignore.names }}" |
| 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 | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 223 | - name: Ensure Management Bridge DHCP |
| 224 | netfile: |
| 225 | src: "{{ compute_node.interfaces.file }}" |
| 226 | state: present |
| 227 | name: mgmtbr |
| 228 | config: "dhcp" |
| 229 | auto: true |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 230 | bridge_ports: "{{ management_iface_list | join(' ') }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 231 | description: "Internal POD management interface" |
| 232 | register: net_changed |
| 233 | when: compute_node.addresses.management == "dhcp" |
| 234 | |
| 235 | - name: Verify Management Bridge DHCP Changed |
| 236 | set_fact: |
| 237 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 238 | |
| 239 | - name: Ensure Management Bridge STATIC |
| 240 | netfile: |
| 241 | src: "{{ compute_node.interfaces.file }}" |
| 242 | state: present |
| 243 | name: mgmtbr |
| 244 | config: static |
| 245 | auto: true |
| 246 | address: "{{ compute_node.addresses.management }}" |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 247 | gateway: "{{ compute_node.gateway.management }}" |
| 248 | broadcast: "{{ compute_node.broadcast.management }}" |
| 249 | bridge_ports: "{{ management_iface_list | join(' ') }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 250 | description: "Internal POD management interface" |
| 251 | register: net_changed |
| 252 | when: compute_node.addresses.management != "dhcp" |
| 253 | |
| 254 | - name: Verify Management Bridge STATIC Changed |
| 255 | set_fact: |
| 256 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 257 | |
| 258 | - name: Ensure Management Bridge Interfaces |
| 259 | netfile: |
| 260 | src: "{{ compute_node.interfaces.file }}" |
| 261 | state: present |
| 262 | auto: true |
| 263 | name: "{{ item }}" |
| 264 | config: manual |
| 265 | description: "Management interface" |
| 266 | register: net_changed |
| 267 | with_items: |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 268 | - "{{ management_iface_list | sort }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 269 | |
| 270 | - name: Verify Management Bridge Interfaces Changed |
| 271 | set_fact: |
| 272 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 273 | |
| 274 | - name: Ensure External Interface DHCP |
| 275 | netfile: |
| 276 | src: "{{ compute_node.interfaces.file }}" |
| 277 | state: present |
| 278 | auto: true |
| 279 | name: "{{ compute_node.interfaces.external }}" |
| 280 | config: dhcp |
| 281 | description: "External interface from POD to Internet (uplink)" |
| 282 | register: net_changed |
| 283 | when: compute_node.interfaces.external and compute_node.addresses.external == "dhcp" |
| 284 | |
| 285 | - name: Verify External Interface DHCP Changed |
| 286 | set_fact: |
| 287 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 288 | |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 289 | - name: Mark Explicitly Excluded Management Bridge Interfaces as Manual |
| 290 | netfile: |
| 291 | src: "{{ compute_node.interfaces.file }}" |
| 292 | state: present |
| 293 | auto: false |
| 294 | name: "{{ item }}" |
| 295 | config: manual |
| 296 | description: "Explicitly Excluded Management Bridge Interface" |
| 297 | register: net_changed |
| 298 | with_items: |
| 299 | - "{{ management_iface_excluded_list | sort }}" |
| 300 | |
| 301 | - name: Verify Explicitly Excluded Management Interfaces Changed |
| 302 | set_fact: |
| 303 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 304 | |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 305 | - name: Ensure External Interface STATIC |
| 306 | netfile: |
| 307 | src: "{{ compute_node.interfaces.file }}" |
| 308 | state: present |
| 309 | auto: true |
| 310 | name: "{{ compute_node.interfaces.external }}" |
| 311 | config: static |
| 312 | address: "{{ compute_node.addresses.external }}" |
David K. Bainbridge | 603ee54 | 2016-10-04 21:11:05 -0700 | [diff] [blame] | 313 | gateway: "{{ compute_node.gateway.external }}" |
| 314 | broadcast: "{{ compute_node.broadcast.external }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 315 | description: "External interface from POD to Internet (uplink)" |
| 316 | register: net_changed |
| 317 | when: compute_node.interfaces.external and compute_node.addresses.external != "dhcp" |
| 318 | |
| 319 | - name: Verify External Interface STATIC Changed |
| 320 | set_fact: |
| 321 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 322 | |
| 323 | - name: Reboot Required |
| 324 | command: /sbin/reboot |
| 325 | async: 0 |
| 326 | poll: 0 |
| 327 | ignore_errors: true |
| 328 | when: reboot_required |
| 329 | tags: |
| 330 | - interface_config |
| 331 | - reboot |
| 332 | |
| 333 | - name: Ensure Port Defined |
| 334 | set_fact: |
| 335 | ansible_ssh_port: 22 |
| 336 | when: ansible_ssh_port is not defined |
| 337 | |
| 338 | - name: Wait For Restart |
| 339 | local_action: wait_for port={{ ansible_ssh_port }} host={{ inventory_hostname }} search_regex=OpenSSH delay=120 timeout=600 connect_timeout=15 |
| 340 | when: reboot_required |
| 341 | tags: |
| 342 | - interface_config |
| 343 | - reboot |