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 | |
| 9 | - name: Gather Interface Information |
| 10 | netinfo: |
| 11 | |
| 12 | - name: Establish Interface Lists |
| 13 | set_fact: |
| 14 | reboot_required: false |
| 15 | fabric_iface_list: [] |
| 16 | nonfabric_iface_list: [] |
| 17 | search_list: "|{{ compute_node.fabric_iface_match }}|" |
| 18 | changed_when: false |
| 19 | |
| 20 | - name: Gather Fabric Interfaces |
| 21 | set_fact: |
| 22 | fabric_iface_list: "{{ fabric_iface_list + [item] }}" |
| 23 | with_items: |
| 24 | - "{{ netinfo.keys() | sort }}" |
| 25 | when: netinfo[item]['module'] is defined and search_list.find('|' + netinfo[item]['module'] + '|') != -1 and ( not compute_node.interfaces.external or item != compute_node.interfaces.external ) |
| 26 | changed_when: false |
| 27 | |
| 28 | - name: Gather Non-Fabric Interfaces |
| 29 | set_fact: |
| 30 | nonfabric_iface_list: "{{ nonfabric_iface_list + [item] }}" |
| 31 | with_items: |
| 32 | - "{{ netinfo.keys() | sort }}" |
| 33 | when: netinfo[item]['module'] is defined and search_list.find('|' + netinfo[item]['module'] + '|') == -1 and ( not compute_node.interfaces.external or item != compute_node.interfaces.external ) |
| 34 | changed_when: false |
| 35 | |
David K. Bainbridge | 039e51d | 2016-09-22 10:12:13 -0400 | [diff] [blame^] | 36 | - name: Ensure Loopback |
| 37 | netfile: |
| 38 | src: "{{ compute_node.interfaces.file }}" |
| 39 | state: present |
| 40 | name: lo |
| 41 | config: loopback |
| 42 | auto: true |
| 43 | description: "Loopback interface" |
| 44 | register: net_changed |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 45 | |
David K. Bainbridge | 039e51d | 2016-09-22 10:12:13 -0400 | [diff] [blame^] | 46 | - name: Verify Loopback Change |
| 47 | set_fact: |
| 48 | reboot_required: "{{ net_changed.changed }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 49 | |
| 50 | - name: Ensure Fabric |
| 51 | netfile: |
| 52 | src: "{{ compute_node.interfaces.file }}" |
| 53 | state: present |
| 54 | name: fabric |
| 55 | config: static |
| 56 | auto: true |
| 57 | address: "{{ compute_node.addresses.fabric }}" |
| 58 | bond-mode: active-backup |
| 59 | bond-miimon: 100 |
| 60 | bond-slaves: none |
| 61 | description: "Leaf - Spine bonded fabric interface" |
| 62 | register: net_changed |
| 63 | |
| 64 | - name: Verify Network Change |
| 65 | set_fact: |
David K. Bainbridge | 039e51d | 2016-09-22 10:12:13 -0400 | [diff] [blame^] | 66 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 67 | |
| 68 | - name: Gather Primary Fabric Interface |
| 69 | set_fact: |
| 70 | fabric_primary_iface: "{{ fabric_iface_list | sort | first }}" |
| 71 | changed_when: false |
| 72 | when: fabric_iface_list|length > 0 |
| 73 | |
| 74 | - name: Ensure Primary Fabric Interface |
| 75 | netfile: |
| 76 | src: "{{ compute_node.interfaces.file }}" |
| 77 | state: present |
| 78 | auto: true |
| 79 | name: "{{ fabric_primary_iface }}" |
| 80 | config: manual |
| 81 | bond-master: fabric |
| 82 | bond-primary: "{{ fabric_primary_iface }}" |
| 83 | description: "Primary fabric interface" |
| 84 | register: net_changed |
| 85 | when: fabric_iface_list|length > 0 |
| 86 | |
| 87 | - name: Verify Primary Fabric Interface Changed |
| 88 | set_fact: |
| 89 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 90 | |
| 91 | - name: Ensure Fabric Interfaces |
| 92 | netfile: |
| 93 | src: "{{ compute_node.interfaces.file }}" |
| 94 | state: present |
| 95 | auto: true |
| 96 | name: "{{ item }}" |
| 97 | config: manual |
| 98 | bond-master: fabric |
| 99 | description: "Fabric interface" |
| 100 | register: net_changed |
| 101 | when: fabric_iface_list|length > 1 and item != fabric_primary_iface |
| 102 | with_items: |
| 103 | - "{{ fabric_iface_list | sort }}" |
| 104 | |
| 105 | - name: Verify Fabric Interfaces Changed |
| 106 | set_fact: |
| 107 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 108 | |
| 109 | - name: Ensure Management Bridge DHCP |
| 110 | netfile: |
| 111 | src: "{{ compute_node.interfaces.file }}" |
| 112 | state: present |
| 113 | name: mgmtbr |
| 114 | config: "dhcp" |
| 115 | auto: true |
| 116 | bridge_ports: "{{ nonfabric_iface_list | join(' ') }}" |
| 117 | description: "Internal POD management interface" |
| 118 | register: net_changed |
| 119 | when: compute_node.addresses.management == "dhcp" |
| 120 | |
| 121 | - name: Verify Management Bridge DHCP Changed |
| 122 | set_fact: |
| 123 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 124 | |
| 125 | - name: Ensure Management Bridge STATIC |
| 126 | netfile: |
| 127 | src: "{{ compute_node.interfaces.file }}" |
| 128 | state: present |
| 129 | name: mgmtbr |
| 130 | config: static |
| 131 | auto: true |
| 132 | address: "{{ compute_node.addresses.management }}" |
| 133 | gateway: "{{ compute_node.gateway.management | default(omit) }}" |
| 134 | broadcast: "{{ compute_node.broadcast.management | default(omit) }}" |
| 135 | bridge_ports: "{{ nonfabric_iface_list | join(' ') }}" |
| 136 | description: "Internal POD management interface" |
| 137 | register: net_changed |
| 138 | when: compute_node.addresses.management != "dhcp" |
| 139 | |
| 140 | - name: Verify Management Bridge STATIC Changed |
| 141 | set_fact: |
| 142 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 143 | |
| 144 | - name: Ensure Management Bridge Interfaces |
| 145 | netfile: |
| 146 | src: "{{ compute_node.interfaces.file }}" |
| 147 | state: present |
| 148 | auto: true |
| 149 | name: "{{ item }}" |
| 150 | config: manual |
| 151 | description: "Management interface" |
| 152 | register: net_changed |
| 153 | with_items: |
| 154 | - "{{ nonfabric_iface_list | sort }}" |
| 155 | |
| 156 | - name: Verify Management Bridge Interfaces Changed |
| 157 | set_fact: |
| 158 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 159 | |
| 160 | - name: Ensure External Interface DHCP |
| 161 | netfile: |
| 162 | src: "{{ compute_node.interfaces.file }}" |
| 163 | state: present |
| 164 | auto: true |
| 165 | name: "{{ compute_node.interfaces.external }}" |
| 166 | config: dhcp |
| 167 | description: "External interface from POD to Internet (uplink)" |
| 168 | register: net_changed |
| 169 | when: compute_node.interfaces.external and compute_node.addresses.external == "dhcp" |
| 170 | |
| 171 | - name: Verify External Interface DHCP Changed |
| 172 | set_fact: |
| 173 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 174 | |
| 175 | - name: Ensure External Interface STATIC |
| 176 | netfile: |
| 177 | src: "{{ compute_node.interfaces.file }}" |
| 178 | state: present |
| 179 | auto: true |
| 180 | name: "{{ compute_node.interfaces.external }}" |
| 181 | config: static |
| 182 | address: "{{ compute_node.addresses.external }}" |
| 183 | gateway: "{{ compute_node.gateway.external | default(omit) }}" |
| 184 | broadcast: "{{ compute_node.broadcast.external | default(omit) }}" |
| 185 | description: "External interface from POD to Internet (uplink)" |
| 186 | register: net_changed |
| 187 | when: compute_node.interfaces.external and compute_node.addresses.external != "dhcp" |
| 188 | |
| 189 | - name: Verify External Interface STATIC Changed |
| 190 | set_fact: |
| 191 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 192 | |
| 193 | - name: Reboot Required |
| 194 | command: /sbin/reboot |
| 195 | async: 0 |
| 196 | poll: 0 |
| 197 | ignore_errors: true |
| 198 | when: reboot_required |
| 199 | tags: |
| 200 | - interface_config |
| 201 | - reboot |
| 202 | |
| 203 | - name: Ensure Port Defined |
| 204 | set_fact: |
| 205 | ansible_ssh_port: 22 |
| 206 | when: ansible_ssh_port is not defined |
| 207 | |
| 208 | - name: Wait For Restart |
| 209 | local_action: wait_for port={{ ansible_ssh_port }} host={{ inventory_hostname }} search_regex=OpenSSH delay=120 timeout=600 connect_timeout=15 |
| 210 | when: reboot_required |
| 211 | tags: |
| 212 | - interface_config |
| 213 | - reboot |