blob: aac29aab265e9c600f7f867b7c33b69e20e15893 [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
Yantian You09d30492019-05-22 20:35:44 +020075- name: Proxy configuration for apt
76 block:
77 - name: Check that the /etc/apt/apt.conf exists
78 stat:
79 path: /etc/apt/apt.conf
80 register: stat_result
81
82 - name: Create /etc/apt/apt.conf, if it doesn't exist
83 file:
84 path: /etc/apt/apt.conf
85 state: touch
86 when: stat_result.stat.exists == False
87
88 - name: Add proxy setting to /etc/apt/apt.conf
89 lineinfile:
90 dest: /etc/apt/apt.conf
91 state: present
92 regexp: "^{{ item.name }}"
93 line: "{{ item.name }} {{ item.value }} "
94 with_items:
95 - {name: 'Acquire::http::Proxy', value: '"{{ idf.proxy_settings.http_proxy }}";' }
96 - {name: 'Acquire::https::Proxy', value: '"{{ idf.proxy_settings.https_proxy }}";' }
97 when:
98 idf.proxy_settings is defined
99
Wenqing Gue1919d82019-04-18 08:56:44 +0200100- name: Reboot the machine
101 shell: "sleep 5 && reboot"
102 async: 1
103 poll: 0
104
105- name: Wait for host to come back to life
106 wait_for_connection:
107 connect_timeout: 10
108 sleep: 5
109 delay: 120
110 timeout: 300
111 register: result
112 until: result | succeeded
113 retries: 3
Yantian You09d30492019-05-22 20:35:44 +0200114
Fatih Degirmencibecbba02019-02-25 00:37:19 +0000115# vim: set ts=2 sw=2 expandtab: