Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 1 | --- |
| 2 | # ============LICENSE_START======================================================= |
| 3 | # Copyright (C) 2019 The Nordix Foundation. All rights reserved. |
| 4 | # ================================================================================ |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # SPDX-License-Identifier: Apache-2.0 |
| 18 | # ============LICENSE_END========================================================= |
| 19 | |
| 20 | - name: Configure modules |
| 21 | lineinfile: |
| 22 | dest: /etc/modules |
| 23 | state: present |
| 24 | create: yes |
| 25 | line: "8021q" |
| 26 | |
| 27 | - name: Add modules |
| 28 | modprobe: |
| 29 | name: 8021q |
| 30 | state: present |
| 31 | |
| 32 | - name: Ensure interfaces.d folder is empty |
| 33 | file: |
| 34 | state: "{{ item }}" |
| 35 | path: "/etc/network/interfaces.d" |
| 36 | with_items: |
| 37 | - absent |
| 38 | - directory |
| 39 | |
| 40 | - name: Ensure /etc/interfaces can source additional files |
| 41 | copy: |
| 42 | content: | |
| 43 | auto lo |
| 44 | iface lo inet loopback |
| 45 | source /etc/network/interfaces.d/*.cfg |
| 46 | dest: "/etc/network/interfaces" |
| 47 | |
| 48 | - name: Configure networking for host |
| 49 | template: |
| 50 | src: "{{ distribution }}.interface.j2" |
| 51 | dest: "/etc/network/interfaces.d/{{ item.name }}.cfg" |
| 52 | with_items: |
| 53 | - { name: "{{ admin_if }}", vlan_id: "{{ (admin_vlan == 'native') | ternary(omit, admin_vlan) }}", nw: "{{ admin_nw }}", ip: "{{ admin_ip }}", gw: "{{ admin_gw }}", dns: "{{ admin_dns }}" } |
| 54 | - { name: "{{ public_if }}", vlan_id: "{{ (public_vlan == 'native') | ternary(omit, public_vlan) }}", nw: "{{ public_nw }}", ip: "{{ public_ip }}", gw: "{{ public_gw }}", dns: "{{ public_dns }}" } |
| 55 | - { name: "{{ mgmt_if }}", vlan_id: "{{ (mgmt_vlan == 'native') | ternary(omit, mgmt_vlan) }}", nw: "{{ mgmt_nw }}", ip: "{{ mgmt_ip }}", gw: "{{ mgmt_gw }}", dns: "{{ mgmt_dns }}" } |
| 56 | - { name: "{{ neutron_if }}", vlan_id: "{{ (neutron_vlan == 'native') | ternary(omit, neutron_vlan) }}", nw: "{{ neutron_nw }}", ip: "{{ neutron_ip }}", gw: "{{ neutron_gw }}", dns: "{{ neutron_dns }}" } |
| 57 | loop_control: |
| 58 | label: "{{ item.name }}" |
| 59 | |
| 60 | - name: Restart network service |
| 61 | shell: "/sbin/ip addr flush dev {{ item }} && /sbin/ifdown -a && /sbin/ifup -a" |
| 62 | async: 15 |
| 63 | poll: 0 |
| 64 | with_items: |
| 65 | - "{{ admin_if }}" |
| 66 | - "{{ public_if }}" |
| 67 | - "{{ mgmt_if }}" |
| 68 | - "{{ neutron_if }}" |
| 69 | |
Fatih Degirmenci | 5d9f6ba | 2019-03-01 14:56:25 +0000 | [diff] [blame^] | 70 | # TODO: The content of /etc/resolv.conf seems to be set randomly |
| 71 | # after network configuration is applied so this is yet another |
| 72 | # DNS workaround to ensure we have the correct nameserver in it |
| 73 | - name: Ensure resolv.conf has the correct content |
| 74 | lineinfile: |
| 75 | path: /etc/resolv.conf |
| 76 | regexp: "^nameserver " |
| 77 | line: "nameserver {{ idf.net_config.public.dns }}" |
| 78 | |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 79 | # vim: set ts=2 sw=2 expandtab: |