blob: 443b456039cc6f39988b5c4ebbaa5f5030e938ca [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
Fatih Degirmenci87c986c2020-01-12 22:35:53 +000024 create: true
Fatih Degirmencibecbba02019-02-25 00:37:19 +000025 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}) }}"
Fatih Degirmenci572223c2019-12-11 13:43:10 +010055 loop: |-
56 {{ ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') |
57 map('extract', hostvars[inventory_hostname]) | selectattr('macaddress','defined') | list }}
58 when: "'.' not in item.device"
Wenqing Gu8d933be2019-04-10 15:14:32 +020059
Vamsi Savaramf82b1a22019-09-20 11:16:46 +000060- name: Filter to include only configured ethernet interfaces
Wenqing Gu8d933be2019-04-10 15:14:32 +020061 set_fact:
Vamsi Savaramf82b1a22019-09-20 11:16:46 +000062 if_mac_dict: "{{ ( if_mac_dict | default({}) ) | combine({item.mac_address: device_mac_dict[item.mac_address]}) }}"
Wenqing Gu8d933be2019-04-10 15:14:32 +020063 loop: "{{ node.interfaces }}"
64
Wenqing Gu236c8452019-03-24 22:07:55 +010065- name: Configure networking for host
Fatih Degirmencibecbba02019-02-25 00:37:19 +000066 template:
Fatih Degirmenci82259612019-05-02 11:44:02 -060067 src: "{{ ansible_os_family }}.interface.j2"
Wenqing Gu8d933be2019-04-10 15:14:32 +020068 dest: "/etc/network/interfaces.d/{{ item.value }}.cfg"
69 loop: "{{ if_mac_dict | dict2items }}"
Fatih Degirmencibecbba02019-02-25 00:37:19 +000070
Wenqing Gu7d498e12019-03-15 15:44:53 +010071- name: Ensure systemd resolved.conf has the correct content
Fatih Degirmenci5d9f6ba2019-03-01 14:56:25 +000072 lineinfile:
Wenqing Gu7d498e12019-03-15 15:44:53 +010073 path: /etc/systemd/resolved.conf
Wenqing Gu738c7c42020-03-25 13:45:49 +010074 regexp: '^#?(DNS|dns)\s*=.*$'
Fatih Degirmenci572223c2019-12-11 13:43:10 +010075 line: "DNS={{ idf.net_config[engine.public_network | default('public')].dns | join(' ') }}"
Wenqing Gufd6d2b82019-04-23 10:34:55 +020076 when: idf.net_config[engine.public_network | default('public')].dns is defined
Wenqing Gu7d498e12019-03-15 15:44:53 +010077
Yantian You09d30492019-05-22 20:35:44 +020078- name: Proxy configuration for apt
79 block:
Fatih Degirmenci87c986c2020-01-12 22:35:53 +000080 - name: Check that the /etc/apt/apt.conf exists
81 stat:
82 path: /etc/apt/apt.conf
83 register: stat_result
Yantian You09d30492019-05-22 20:35:44 +020084
Fatih Degirmenci87c986c2020-01-12 22:35:53 +000085 - name: Create /etc/apt/apt.conf, if it doesn't exist
86 file:
87 path: /etc/apt/apt.conf
88 state: touch
89 when: not stat_result.stat.exists
Yantian You09d30492019-05-22 20:35:44 +020090
Fatih Degirmenci87c986c2020-01-12 22:35:53 +000091 - name: Add proxy setting to /etc/apt/apt.conf
92 lineinfile:
93 dest: /etc/apt/apt.conf
94 state: present
95 regexp: "^{{ item.name }}"
96 line: "{{ item.name }} {{ item.value }} "
97 with_items:
98 - {name: 'Acquire::http::Proxy', value: '"{{ idf.proxy_settings.http_proxy }}";'}
99 - {name: 'Acquire::https::Proxy', value: '"{{ idf.proxy_settings.https_proxy }}";'}
Fatih Degirmenci572223c2019-12-11 13:43:10 +0100100 when: idf.proxy_settings is defined
Yantian You09d30492019-05-22 20:35:44 +0200101
Wenqing Gue1919d82019-04-18 08:56:44 +0200102- name: Reboot the machine
103 shell: "sleep 5 && reboot"
104 async: 1
105 poll: 0
Fatih Degirmenci572223c2019-12-11 13:43:10 +0100106 changed_when: false
Wenqing Gue1919d82019-04-18 08:56:44 +0200107
108- name: Wait for host to come back to life
109 wait_for_connection:
110 connect_timeout: 10
111 sleep: 5
112 delay: 120
113 timeout: 300
114 register: result
Fatih Degirmencie25be7f2020-03-15 22:28:54 +0000115 until: result is succeeded
Wenqing Gue1919d82019-04-18 08:56:44 +0200116 retries: 3
Yantian You09d30492019-05-22 20:35:44 +0200117
Fatih Degirmencibecbba02019-02-25 00:37:19 +0000118# vim: set ts=2 sw=2 expandtab: