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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
20 - name: Get node names from IDF
22 node_name: "{{ item.key }}"
23 with_dict: "{{ idf.kubespray.hostnames }}"
24 when: item.value == inventory_hostname
26 - name: Set facts for the nodes
28 node: "{{ nodes | selectattr('name', 'equalto', node_name) | first }}"
30 - name: Configure modules
42 - name: Ensure interfaces.d folder is empty
45 path: "/etc/network/interfaces.d"
50 - name: Ensure /etc/interfaces can source additional files
54 iface lo inet loopback
55 source /etc/network/interfaces.d/*.cfg
56 dest: "/etc/network/interfaces"
58 - name: Compute mapping dict from mac address to device name
60 device_mac_dict: "{{ (device_mac_dict | default({})) | combine({item.macaddress: item.device}) }}"
62 {{ ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') |
63 map('extract', hostvars[inventory_hostname]) | selectattr('macaddress','defined') | list }}
64 when: "'.' not in item.device"
66 - name: Filter to include only configured ethernet interfaces
68 if_mac_dict: "{{ ( if_mac_dict | default({}) ) | combine({item.mac_address: device_mac_dict[item.mac_address]}) }}"
69 loop: "{{ node.interfaces }}"
71 - name: Configure networking for host
73 src: "Debian.interface.j2"
74 dest: "/etc/network/interfaces.d/{{ item.value }}.cfg"
75 loop: "{{ if_mac_dict | dict2items }}"
77 - name: Reboot the machine
78 shell: "sleep 5 && reboot"
83 - name: Wait for host to come back to life
90 until: result is succeeded