Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 1 | --- |
| 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 Gu | 7482272 | 2019-03-21 10:26:30 +0100 | [diff] [blame] | 32 | # TODO: we need to look into how to configure with netplan for ubuntu 18 |
Wenqing Gu | 236c845 | 2019-03-24 22:07:55 +0100 | [diff] [blame] | 33 | # 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 Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 37 | file: |
| 38 | state: "{{ item }}" |
| 39 | path: "/etc/network/interfaces.d" |
| 40 | with_items: |
Wenqing Gu | 236c845 | 2019-03-24 22:07:55 +0100 | [diff] [blame] | 41 | - absent |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 42 | - 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 Gu | 8d933be | 2019-04-10 15:14:32 +0200 | [diff] [blame] | 52 | - 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 Gu | 236c845 | 2019-03-24 22:07:55 +0100 | [diff] [blame] | 62 | - name: Configure networking for host |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 63 | template: |
Fatih Degirmenci | 8225961 | 2019-05-02 11:44:02 -0600 | [diff] [blame] | 64 | src: "{{ ansible_os_family }}.interface.j2" |
Wenqing Gu | 8d933be | 2019-04-10 15:14:32 +0200 | [diff] [blame] | 65 | dest: "/etc/network/interfaces.d/{{ item.value }}.cfg" |
| 66 | loop: "{{ if_mac_dict | dict2items }}" |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 67 | |
Wenqing Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 68 | - name: Ensure systemd resolved.conf has the correct content |
Fatih Degirmenci | 5d9f6ba | 2019-03-01 14:56:25 +0000 | [diff] [blame] | 69 | lineinfile: |
Wenqing Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 70 | path: /etc/systemd/resolved.conf |
| 71 | regexp: "^#?DNS=.*$" |
Wenqing Gu | fd6d2b8 | 2019-04-23 10:34:55 +0200 | [diff] [blame] | 72 | 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 Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 74 | |
Yantian You | 09d3049 | 2019-05-22 20:35:44 +0200 | [diff] [blame^] | 75 | - 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 Gu | e1919d8 | 2019-04-18 08:56:44 +0200 | [diff] [blame] | 100 | - 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 You | 09d3049 | 2019-05-22 20:35:44 +0200 | [diff] [blame^] | 114 | |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 115 | # vim: set ts=2 sw=2 expandtab: |