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 |
Fatih Degirmenci | 87c986c | 2020-01-12 22:35:53 +0000 | [diff] [blame] | 24 | create: true |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 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}) }}" |
Fatih Degirmenci | 572223c | 2019-12-11 13:43:10 +0100 | [diff] [blame] | 55 | 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 Gu | 8d933be | 2019-04-10 15:14:32 +0200 | [diff] [blame] | 59 | |
Vamsi Savaram | f82b1a2 | 2019-09-20 11:16:46 +0000 | [diff] [blame] | 60 | - name: Filter to include only configured ethernet interfaces |
Wenqing Gu | 8d933be | 2019-04-10 15:14:32 +0200 | [diff] [blame] | 61 | set_fact: |
Vamsi Savaram | f82b1a2 | 2019-09-20 11:16:46 +0000 | [diff] [blame] | 62 | if_mac_dict: "{{ ( if_mac_dict | default({}) ) | combine({item.mac_address: device_mac_dict[item.mac_address]}) }}" |
Wenqing Gu | 8d933be | 2019-04-10 15:14:32 +0200 | [diff] [blame] | 63 | loop: "{{ node.interfaces }}" |
| 64 | |
Wenqing Gu | 236c845 | 2019-03-24 22:07:55 +0100 | [diff] [blame] | 65 | - name: Configure networking for host |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 66 | template: |
Fatih Degirmenci | 8225961 | 2019-05-02 11:44:02 -0600 | [diff] [blame] | 67 | src: "{{ ansible_os_family }}.interface.j2" |
Wenqing Gu | 8d933be | 2019-04-10 15:14:32 +0200 | [diff] [blame] | 68 | dest: "/etc/network/interfaces.d/{{ item.value }}.cfg" |
| 69 | loop: "{{ if_mac_dict | dict2items }}" |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 70 | |
Wenqing Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 71 | - name: Ensure systemd resolved.conf has the correct content |
Fatih Degirmenci | 5d9f6ba | 2019-03-01 14:56:25 +0000 | [diff] [blame] | 72 | lineinfile: |
Wenqing Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 73 | path: /etc/systemd/resolved.conf |
Wenqing Gu | 738c7c4 | 2020-03-25 13:45:49 +0100 | [diff] [blame] | 74 | regexp: '^#?(DNS|dns)\s*=.*$' |
Fatih Degirmenci | 572223c | 2019-12-11 13:43:10 +0100 | [diff] [blame] | 75 | line: "DNS={{ idf.net_config[engine.public_network | default('public')].dns | join(' ') }}" |
Wenqing Gu | fd6d2b8 | 2019-04-23 10:34:55 +0200 | [diff] [blame] | 76 | when: idf.net_config[engine.public_network | default('public')].dns is defined |
Wenqing Gu | 7d498e1 | 2019-03-15 15:44:53 +0100 | [diff] [blame] | 77 | |
Yantian You | 09d3049 | 2019-05-22 20:35:44 +0200 | [diff] [blame] | 78 | - name: Proxy configuration for apt |
| 79 | block: |
Fatih Degirmenci | 87c986c | 2020-01-12 22:35:53 +0000 | [diff] [blame] | 80 | - name: Check that the /etc/apt/apt.conf exists |
| 81 | stat: |
| 82 | path: /etc/apt/apt.conf |
| 83 | register: stat_result |
Yantian You | 09d3049 | 2019-05-22 20:35:44 +0200 | [diff] [blame] | 84 | |
Fatih Degirmenci | 87c986c | 2020-01-12 22:35:53 +0000 | [diff] [blame] | 85 | - 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 You | 09d3049 | 2019-05-22 20:35:44 +0200 | [diff] [blame] | 90 | |
Fatih Degirmenci | 87c986c | 2020-01-12 22:35:53 +0000 | [diff] [blame] | 91 | - 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 Degirmenci | 572223c | 2019-12-11 13:43:10 +0100 | [diff] [blame] | 100 | when: idf.proxy_settings is defined |
Yantian You | 09d3049 | 2019-05-22 20:35:44 +0200 | [diff] [blame] | 101 | |
Wenqing Gu | e1919d8 | 2019-04-18 08:56:44 +0200 | [diff] [blame] | 102 | - name: Reboot the machine |
| 103 | shell: "sleep 5 && reboot" |
| 104 | async: 1 |
| 105 | poll: 0 |
Fatih Degirmenci | 572223c | 2019-12-11 13:43:10 +0100 | [diff] [blame] | 106 | changed_when: false |
Wenqing Gu | e1919d8 | 2019-04-18 08:56:44 +0200 | [diff] [blame] | 107 | |
| 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 Degirmenci | e25be7f | 2020-03-15 22:28:54 +0000 | [diff] [blame^] | 115 | until: result is succeeded |
Wenqing Gu | e1919d8 | 2019-04-18 08:56:44 +0200 | [diff] [blame] | 116 | retries: 3 |
Yantian You | 09d3049 | 2019-05-22 20:35:44 +0200 | [diff] [blame] | 117 | |
Fatih Degirmenci | becbba0 | 2019-02-25 00:37:19 +0000 | [diff] [blame] | 118 | # vim: set ts=2 sw=2 expandtab: |