blob: 8b2d69f8fe06d5e6dfcbc10903f0f5af3f3bda78 [file] [log] [blame]
---
# ============LICENSE_START=======================================================
# Copyright (C) 2019 The Nordix Foundation. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# ============LICENSE_END=========================================================
- name: Configure modules
lineinfile:
dest: /etc/modules
state: present
create: yes
line: "8021q"
- name: Add modules
modprobe:
name: 8021q
state: present
# TODO: we need to look into how to configure with netplan for ubuntu 18
# For ubuntu 16.04, the way of not cleaning up the interfaces.d directory has small
# risk if the directory has other configuration files named other than the interfaces
# that we are configuring. Practically we do not have this issue today.
- name: Ensure interfaces.d folder exists
file:
state: "{{ item }}"
path: "/etc/network/interfaces.d"
with_items:
- directory
- name: Ensure /etc/interfaces can source additional files
copy:
content: |
auto lo
iface lo inet loopback
source /etc/network/interfaces.d/*.cfg
dest: "/etc/network/interfaces"
- name: Ensures /tmp/network_itf directory exists and empty
file:
state: "{{ item }}"
path: "/tmp/network_itf"
with_items:
- absent
- directory
- name: Prepare the networking configuration on the host
template:
src: "{{ distribution }}.interface.j2"
dest: "/tmp/network_itf/{{ item.name }}.cfg"
with_items:
- { name: "{{ admin_if }}", vlan_id: "{{ (admin_vlan == 'native') | ternary(omit, admin_vlan) }}", nw: "{{ admin_nw }}", ip: "{{ admin_ip }}", gw: "{{ admin_gw }}"}
- { name: "{{ public_if }}", vlan_id: "{{ (public_vlan == 'native') | ternary(omit, public_vlan) }}", nw: "{{ public_nw }}", ip: "{{ public_ip }}", gw: "{{ public_gw }}"}
- { name: "{{ mgmt_if }}", vlan_id: "{{ (mgmt_vlan == 'native') | ternary(omit, mgmt_vlan) }}", nw: "{{ mgmt_nw }}", ip: "{{ mgmt_ip }}", gw: "{{ mgmt_gw }}"}
- { name: "{{ neutron_if }}", vlan_id: "{{ (neutron_vlan == 'native') | ternary(omit, neutron_vlan) }}", nw: "{{ neutron_nw }}", ip: "{{ neutron_ip }}", gw: "{{ neutron_gw }}"}
loop_control:
label: "{{ item.name }}"
- name: Configure and restart the network service
shell: "/sbin/ip addr flush dev {{ item }} && /sbin/ifdown {{ item }} && cp /tmp/network_itf/{{ item }}.cfg /etc/network/interfaces.d/ && /sbin/ifup {{ item }}"
async: 15
poll: 0
with_items:
- "{{ admin_if }}"
- "{{ public_if }}"
- "{{ mgmt_if }}"
- "{{ neutron_if }}"
- name: Ensure systemd resolved.conf has the correct content
lineinfile:
path: /etc/systemd/resolved.conf
regexp: "^#?DNS=.*$"
line: "DNS={{ idf.net_config.public.dns | join(' ')}}"
when: idf.net_config.public.dns is defined
- name: Restart systemd-resolved service
service:
name: systemd-resolved
state: restarted
# vim: set ts=2 sw=2 expandtab: