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 | |
Wenqing Gu | 7482272 | 2019-03-21 10:26:30 +0100 | [diff] [blame^] | 32 | # TODO: we need to look into how to configure with netplan for ubuntu 18 |
| 33 | # For ubuntu 16.04, the way of not cleaning up the interfaces.d directory has small |
| 34 | # risk if the directory has other configuration files named other than the interfaces |
| 35 | # that we are configuring. Practically we do not have this issue today. |
| 36 | - name: Ensure interfaces.d folder exists |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 37 | file: |
| 38 | state: "{{ item }}" |
| 39 | path: "/etc/network/interfaces.d" |
| 40 | with_items: |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 41 | - directory |
| 42 | |
| 43 | - name: Ensure /etc/interfaces can source additional files |
| 44 | copy: |
| 45 | content: | |
| 46 | auto lo |
| 47 | iface lo inet loopback |
| 48 | source /etc/network/interfaces.d/*.cfg |
| 49 | dest: "/etc/network/interfaces" |
| 50 | |
Wenqing Gu | 7482272 | 2019-03-21 10:26:30 +0100 | [diff] [blame^] | 51 | - name: Ensures /tmp/network_itf directory exists and empty |
| 52 | file: |
| 53 | state: "{{ item }}" |
| 54 | path: "/tmp/network_itf" |
| 55 | with_items: |
| 56 | - absent |
| 57 | - directory |
| 58 | |
| 59 | - name: Prepare the networking configuration on the host |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 60 | template: |
| 61 | src: "{{ distribution }}.interface.j2" |
Wenqing Gu | 7482272 | 2019-03-21 10:26:30 +0100 | [diff] [blame^] | 62 | dest: "/tmp/network_itf/{{ item.name }}.cfg" |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 63 | with_items: |
Wenqing Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 64 | - { name: "{{ admin_if }}", vlan_id: "{{ (admin_vlan == 'native') | ternary(omit, admin_vlan) }}", nw: "{{ admin_nw }}", ip: "{{ admin_ip }}", gw: "{{ admin_gw }}"} |
| 65 | - { name: "{{ public_if }}", vlan_id: "{{ (public_vlan == 'native') | ternary(omit, public_vlan) }}", nw: "{{ public_nw }}", ip: "{{ public_ip }}", gw: "{{ public_gw }}"} |
| 66 | - { name: "{{ mgmt_if }}", vlan_id: "{{ (mgmt_vlan == 'native') | ternary(omit, mgmt_vlan) }}", nw: "{{ mgmt_nw }}", ip: "{{ mgmt_ip }}", gw: "{{ mgmt_gw }}"} |
| 67 | - { name: "{{ neutron_if }}", vlan_id: "{{ (neutron_vlan == 'native') | ternary(omit, neutron_vlan) }}", nw: "{{ neutron_nw }}", ip: "{{ neutron_ip }}", gw: "{{ neutron_gw }}"} |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 68 | loop_control: |
| 69 | label: "{{ item.name }}" |
| 70 | |
Wenqing Gu | 7482272 | 2019-03-21 10:26:30 +0100 | [diff] [blame^] | 71 | - name: Configure and restart the network service |
| 72 | shell: "/sbin/ip addr flush dev {{ item }} && /sbin/ifdown {{ item }} && cp /tmp/network_itf/{{ item }}.cfg /etc/network/interfaces.d/ && /sbin/ifup {{ item }}" |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 73 | async: 15 |
| 74 | poll: 0 |
| 75 | with_items: |
| 76 | - "{{ admin_if }}" |
| 77 | - "{{ public_if }}" |
| 78 | - "{{ mgmt_if }}" |
| 79 | - "{{ neutron_if }}" |
| 80 | |
Wenqing Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 81 | - name: Ensure systemd resolved.conf has the correct content |
Fatih Degirmenci | 5d9f6ba | 2019-03-01 14:56:25 +0000 | [diff] [blame] | 82 | lineinfile: |
Wenqing Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 83 | path: /etc/systemd/resolved.conf |
| 84 | regexp: "^#?DNS=.*$" |
| 85 | line: "DNS={{ idf.net_config.public.dns | join(' ')}}" |
Wenqing Gu | 7482272 | 2019-03-21 10:26:30 +0100 | [diff] [blame^] | 86 | when: idf.net_config.public.dns is defined |
Wenqing Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 87 | |
| 88 | - name: Restart systemd-resolved service |
| 89 | service: |
Wenqing Gu | 7482272 | 2019-03-21 10:26:30 +0100 | [diff] [blame^] | 90 | name: systemd-resolved |
Wenqing Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 91 | state: restarted |
Fatih Degirmenci | 5d9f6ba | 2019-03-01 14:56:25 +0000 | [diff] [blame] | 92 | |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 93 | # vim: set ts=2 sw=2 expandtab: |