blob: 8b2d69f8fe06d5e6dfcbc10903f0f5af3f3bda78 [file] [log] [blame]
Fatih Degirmencibecbba02019-02-25 00:37:19 +00001---
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 Gu74822722019-03-21 10:26:30 +010032# 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 Degirmencibecbba02019-02-25 00:37:19 +000037 file:
38 state: "{{ item }}"
39 path: "/etc/network/interfaces.d"
40 with_items:
Fatih Degirmencibecbba02019-02-25 00:37:19 +000041 - 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 Gu74822722019-03-21 10:26:30 +010051- 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 Degirmencibecbba02019-02-25 00:37:19 +000060 template:
61 src: "{{ distribution }}.interface.j2"
Wenqing Gu74822722019-03-21 10:26:30 +010062 dest: "/tmp/network_itf/{{ item.name }}.cfg"
Fatih Degirmencibecbba02019-02-25 00:37:19 +000063 with_items:
Wenqing Gu7d498e12019-03-15 15:44:53 +010064 - { 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 Degirmencibecbba02019-02-25 00:37:19 +000068 loop_control:
69 label: "{{ item.name }}"
70
Wenqing Gu74822722019-03-21 10:26:30 +010071- 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 Degirmencibecbba02019-02-25 00:37:19 +000073 async: 15
74 poll: 0
75 with_items:
76 - "{{ admin_if }}"
77 - "{{ public_if }}"
78 - "{{ mgmt_if }}"
79 - "{{ neutron_if }}"
80
Wenqing Gu7d498e12019-03-15 15:44:53 +010081- name: Ensure systemd resolved.conf has the correct content
Fatih Degirmenci5d9f6ba2019-03-01 14:56:25 +000082 lineinfile:
Wenqing Gu7d498e12019-03-15 15:44:53 +010083 path: /etc/systemd/resolved.conf
84 regexp: "^#?DNS=.*$"
85 line: "DNS={{ idf.net_config.public.dns | join(' ')}}"
Wenqing Gu74822722019-03-21 10:26:30 +010086 when: idf.net_config.public.dns is defined
Wenqing Gu7d498e12019-03-15 15:44:53 +010087
88- name: Restart systemd-resolved service
89 service:
Wenqing Gu74822722019-03-21 10:26:30 +010090 name: systemd-resolved
Wenqing Gu7d498e12019-03-15 15:44:53 +010091 state: restarted
Fatih Degirmenci5d9f6ba2019-03-01 14:56:25 +000092
Fatih Degirmencibecbba02019-02-25 00:37:19 +000093# vim: set ts=2 sw=2 expandtab: