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 | 5135c55 | 2016-09-25 18:47:43 -0700 | [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 | 5135c55 | 2016-09-25 18:47:43 -0700 | [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 | 5135c55 | 2016-09-25 18:47:43 -0700 | [diff] [blame] | 66 | reboot_required: "{{ net_changed.changed }}" |
| 67 | # reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame] | 68 | |
| 69 | - name: Gather Primary Fabric Interface |
| 70 | set_fact: |
| 71 | fabric_primary_iface: "{{ fabric_iface_list | sort | first }}" |
| 72 | changed_when: false |
| 73 | when: fabric_iface_list|length > 0 |
| 74 | |
| 75 | - name: Ensure Primary Fabric Interface |
| 76 | netfile: |
| 77 | src: "{{ compute_node.interfaces.file }}" |
| 78 | state: present |
| 79 | auto: true |
| 80 | name: "{{ fabric_primary_iface }}" |
| 81 | config: manual |
| 82 | bond-master: fabric |
| 83 | bond-primary: "{{ fabric_primary_iface }}" |
| 84 | description: "Primary fabric interface" |
| 85 | register: net_changed |
| 86 | when: fabric_iface_list|length > 0 |
| 87 | |
| 88 | - name: Verify Primary Fabric Interface Changed |
| 89 | set_fact: |
| 90 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 91 | |
| 92 | - name: Ensure Fabric Interfaces |
| 93 | netfile: |
| 94 | src: "{{ compute_node.interfaces.file }}" |
| 95 | state: present |
| 96 | auto: true |
| 97 | name: "{{ item }}" |
| 98 | config: manual |
| 99 | bond-master: fabric |
| 100 | description: "Fabric interface" |
| 101 | register: net_changed |
| 102 | when: fabric_iface_list|length > 1 and item != fabric_primary_iface |
| 103 | with_items: |
| 104 | - "{{ fabric_iface_list | sort }}" |
| 105 | |
| 106 | - name: Verify Fabric Interfaces Changed |
| 107 | set_fact: |
| 108 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 109 | |
| 110 | - name: Ensure Management Bridge DHCP |
| 111 | netfile: |
| 112 | src: "{{ compute_node.interfaces.file }}" |
| 113 | state: present |
| 114 | name: mgmtbr |
| 115 | config: "dhcp" |
| 116 | auto: true |
| 117 | bridge_ports: "{{ nonfabric_iface_list | join(' ') }}" |
| 118 | description: "Internal POD management interface" |
| 119 | register: net_changed |
| 120 | when: compute_node.addresses.management == "dhcp" |
| 121 | |
| 122 | - name: Verify Management Bridge DHCP Changed |
| 123 | set_fact: |
| 124 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 125 | |
| 126 | - name: Ensure Management Bridge STATIC |
| 127 | netfile: |
| 128 | src: "{{ compute_node.interfaces.file }}" |
| 129 | state: present |
| 130 | name: mgmtbr |
| 131 | config: static |
| 132 | auto: true |
| 133 | address: "{{ compute_node.addresses.management }}" |
| 134 | gateway: "{{ compute_node.gateway.management | default(omit) }}" |
| 135 | broadcast: "{{ compute_node.broadcast.management | default(omit) }}" |
| 136 | bridge_ports: "{{ nonfabric_iface_list | join(' ') }}" |
| 137 | description: "Internal POD management interface" |
| 138 | register: net_changed |
| 139 | when: compute_node.addresses.management != "dhcp" |
| 140 | |
| 141 | - name: Verify Management Bridge STATIC Changed |
| 142 | set_fact: |
| 143 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 144 | |
| 145 | - name: Ensure Management Bridge Interfaces |
| 146 | netfile: |
| 147 | src: "{{ compute_node.interfaces.file }}" |
| 148 | state: present |
| 149 | auto: true |
| 150 | name: "{{ item }}" |
| 151 | config: manual |
| 152 | description: "Management interface" |
| 153 | register: net_changed |
| 154 | with_items: |
| 155 | - "{{ nonfabric_iface_list | sort }}" |
| 156 | |
| 157 | - name: Verify Management Bridge Interfaces Changed |
| 158 | set_fact: |
| 159 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 160 | |
| 161 | - name: Ensure External Interface DHCP |
| 162 | netfile: |
| 163 | src: "{{ compute_node.interfaces.file }}" |
| 164 | state: present |
| 165 | auto: true |
| 166 | name: "{{ compute_node.interfaces.external }}" |
| 167 | config: dhcp |
| 168 | description: "External interface from POD to Internet (uplink)" |
| 169 | register: net_changed |
| 170 | when: compute_node.interfaces.external and compute_node.addresses.external == "dhcp" |
| 171 | |
| 172 | - name: Verify External Interface DHCP Changed |
| 173 | set_fact: |
| 174 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 175 | |
| 176 | - name: Ensure External Interface STATIC |
| 177 | netfile: |
| 178 | src: "{{ compute_node.interfaces.file }}" |
| 179 | state: present |
| 180 | auto: true |
| 181 | name: "{{ compute_node.interfaces.external }}" |
| 182 | config: static |
| 183 | address: "{{ compute_node.addresses.external }}" |
| 184 | gateway: "{{ compute_node.gateway.external | default(omit) }}" |
| 185 | broadcast: "{{ compute_node.broadcast.external | default(omit) }}" |
| 186 | description: "External interface from POD to Internet (uplink)" |
| 187 | register: net_changed |
| 188 | when: compute_node.interfaces.external and compute_node.addresses.external != "dhcp" |
| 189 | |
| 190 | - name: Verify External Interface STATIC Changed |
| 191 | set_fact: |
| 192 | reboot_required: "{{ reboot_required }} or {{ net_changed.changed }}" |
| 193 | |
| 194 | - name: Reboot Required |
| 195 | command: /sbin/reboot |
| 196 | async: 0 |
| 197 | poll: 0 |
| 198 | ignore_errors: true |
| 199 | when: reboot_required |
| 200 | tags: |
| 201 | - interface_config |
| 202 | - reboot |
| 203 | |
| 204 | - name: Ensure Port Defined |
| 205 | set_fact: |
| 206 | ansible_ssh_port: 22 |
| 207 | when: ansible_ssh_port is not defined |
| 208 | |
| 209 | - name: Wait For Restart |
| 210 | local_action: wait_for port={{ ansible_ssh_port }} host={{ inventory_hostname }} search_regex=OpenSSH delay=120 timeout=600 connect_timeout=15 |
| 211 | when: reboot_required |
| 212 | tags: |
| 213 | - interface_config |
| 214 | - reboot |