blob: 729fed81c77d4f2bed241eed6e232039d55e6cb5 [file] [log] [blame]
Fatih Degirmenci82259612019-05-02 11:44:02 -06001---
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
32- name: Compute mapping dict from mac address to device name
33 set_fact:
34 device_mac_dict: "{{ (device_mac_dict | default({})) | combine({item.macaddress: item.device}) }}"
35 with_items:
36 - "{{ ansible_interfaces | map('regex_replace', '-', '_') | map('regex_replace', '^', 'ansible_') | map('extract', hostvars[inventory_hostname]) | selectattr('macaddress','defined') | list }}"
37
38- name: Compute mapping dict from mac address to interface name (device name with/without VLAN info)
39 set_fact:
40 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) }) }}"
41 with_items:
42 - "{{ node.interfaces }}"
43
44- name: Configure networking for host
45 template:
46 src: "{{ ansible_os_family }}.interface.j2"
47 dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.value }}"
48 with_items:
49 - "{{ if_mac_dict | dict2items }}"
50
51- name: Restart network
52 service:
53 name: network
54 state: restarted
55
56# vim: set ts=2 sw=2 expandtab: