blob: ac9a9ff180461827c463552abf6fab1b047d3e09 [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
Wenqing Gu236c8452019-03-24 22:07:55 +010033# Today we perform a reboot after network related confiugration changes
34# to make sure the changes are persistent and prevent various issues.
35
36- name: Ensure interfaces.d folder is empty
Fatih Degirmencibecbba02019-02-25 00:37:19 +000037 file:
38 state: "{{ item }}"
39 path: "/etc/network/interfaces.d"
40 with_items:
Wenqing Gu236c8452019-03-24 22:07:55 +010041 - absent
Fatih Degirmencibecbba02019-02-25 00:37:19 +000042 - directory
43
44- name: Ensure /etc/interfaces can source additional files
45 copy:
46 content: |
47 auto lo
48 iface lo inet loopback
49 source /etc/network/interfaces.d/*.cfg
50 dest: "/etc/network/interfaces"
51
Wenqing Gu8d933be2019-04-10 15:14:32 +020052- name: Compute mapping dict from mac address to device name
53 set_fact:
54 device_mac_dict: "{{ (device_mac_dict | default({})) | combine({item.macaddress: item.device}) }}"
55 loop: "{{ ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') | map('extract', hostvars[inventory_hostname]) | selectattr('macaddress','defined') | list }}"
56
57- name: Compute mapping dict from mac address to interface name (device name with/without VLAN info)
58 set_fact:
59 if_mac_dict: "{{ ( if_mac_dict | default({}) ) | combine({item.mac_address: (item.vlan == 'native') | ternary(device_mac_dict[item.mac_address], device_mac_dict[item.mac_address] + '.' + item.vlan) }) }}"
60 loop: "{{ node.interfaces }}"
61
Wenqing Gu236c8452019-03-24 22:07:55 +010062- name: Configure networking for host
Fatih Degirmencibecbba02019-02-25 00:37:19 +000063 template:
Fatih Degirmenci82259612019-05-02 11:44:02 -060064 src: "{{ ansible_os_family }}.interface.j2"
Wenqing Gu8d933be2019-04-10 15:14:32 +020065 dest: "/etc/network/interfaces.d/{{ item.value }}.cfg"
66 loop: "{{ if_mac_dict | dict2items }}"
Fatih Degirmencibecbba02019-02-25 00:37:19 +000067
Wenqing Gu7d498e12019-03-15 15:44:53 +010068- name: Ensure systemd resolved.conf has the correct content
Fatih Degirmenci5d9f6ba2019-03-01 14:56:25 +000069 lineinfile:
Wenqing Gu7d498e12019-03-15 15:44:53 +010070 path: /etc/systemd/resolved.conf
71 regexp: "^#?DNS=.*$"
Wenqing Gufd6d2b82019-04-23 10:34:55 +020072 line: "DNS={{ idf.net_config[engine.public_network | default('public')].dns | join(' ')}}"
73 when: idf.net_config[engine.public_network | default('public')].dns is defined
Wenqing Gu7d498e12019-03-15 15:44:53 +010074
Wenqing Gue1919d82019-04-18 08:56:44 +020075- name: Reboot the machine
76 shell: "sleep 5 && reboot"
77 async: 1
78 poll: 0
79
80- name: Wait for host to come back to life
81 wait_for_connection:
82 connect_timeout: 10
83 sleep: 5
84 delay: 120
85 timeout: 300
86 register: result
87 until: result | succeeded
88 retries: 3
Fatih Degirmencibecbba02019-02-25 00:37:19 +000089# vim: set ts=2 sw=2 expandtab: