This repository was archived by the owner on Oct 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlookup_interface_names.yml
117 lines (108 loc) · 4.02 KB
/
lookup_interface_names.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
# Copyright 2019 IBM Corp.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Lookup device names for any physical interface with rename=false
hosts: client_nodes
gather_facts: True
vars:
mac_to_device: {}
set_macs: {}
tasks:
- name: Create dictionary mapping MAC addresses to device names
set_fact:
mac_to_device: "{{ mac_to_device| combine( \
{vars['ansible_' + item]['macaddress']: item} ) }}"
with_items: "{{ ansible_interfaces }}"
when: vars['ansible_' + item]['macaddress'] is defined
- name: Create list of PXE MACs with rename=false in inventory
set_fact:
set_macs: "{{ set_macs| combine( {item.0: mac_to_device[item.0|lower]} ) }}"
with_together:
- "{{ vars['pxe']['macs'] }}"
- "{{ vars['pxe']['rename'] }}"
when:
- item.0 is not none
- not item.1
- name: Create list of data MACs with rename=false in inventory
set_fact:
set_macs: "{{ set_macs| combine( {item.0: mac_to_device[item.0|lower]} ) }}"
with_together:
- "{{ vars['data']['macs'] }}"
- "{{ vars['data']['rename'] }}"
when:
- item.0 is not none
- not item.1
- name: Modify interface device names in inventory
hosts: deployer
vars:
set_macs_all: {}
tasks:
- name: Combine client node tables
set_fact:
set_macs_all: "{{ set_macs_all| combine(hostvars[item]['set_macs']) }}"
with_items: "{{ groups['client_nodes'] }}"
when: hostvars[item]['set_macs'] is defined
- name: Call 'inv_set_interface_names.py' with lookup data
command: "{{ python_executable }} \
{{ scripts_path }}/python/inv_set_interface_names.py \
{{ item.key }} {{ item.value }} {{ config_path }}"
with_dict: "{{ set_macs_all }}"
- name: Disable any ifcfg scripts that will become stale after renames
hosts: client_nodes
gather_facts: True
vars:
stale_devs: []
tasks:
- block:
- name: Create list of PXE devices that will be renamed
set_fact:
stale_devs: "{{ stale_devs + [mac_to_device[item.0|lower]] }}"
with_together:
- "{{ vars['pxe']['macs'] }}"
- "{{ vars['pxe']['rename'] }}"
- "{{ vars['pxe']['devices'] }}"
when:
- item.0 is not none
- item.1
- item.2 != mac_to_device[item.0|lower]
- name: Create list of Data devices that will be renamed
set_fact:
stale_devs: "{{ stale_devs + [mac_to_device[item.0|lower]] }}"
with_together:
- "{{ vars['data']['macs'] }}"
- "{{ vars['data']['rename'] }}"
- "{{ vars['data']['devices'] }}"
when:
- item.0 is not none
- item.1
- item.2 != mac_to_device[item.0|lower]
- name: Find all interface configuration scripts
find:
paths: /etc/sysconfig/network-scripts/
patterns: 'ifcfg-*'
register: ifcfg_scripts
- name: Disable any interface scripts that will become stale
lineinfile:
path: "{{ item.path }}"
regexp: '^ONBOOT='
line: 'ONBOOT=no # Disabled by POWER-Up'
when:
- (item.path | basename).split('-')[1] != 'lo'
- (item.path | basename).split('-')[1] in stale_devs
loop: "{{ ifcfg_scripts.files }}"
when: (ansible_distribution == 'CentOS' or
ansible_distribution == 'RedHat')
...