Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit c2918d2

Browse files
authored
fix: Only disable stale 'ifcfg' scripts (#358)
Commit 28743e1 (PR #323) disabled "ONBOOT" loading of _any_ ifcfg script with a device name that didn't match a physical device name in inventory. This commit changes the logic to _only_ disable "ONBOOT" in ifcfg names match the original device name of a *changed* interface. All other interface configuration scripts are left alone.
1 parent b83a8fa commit c2918d2

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
lines changed

playbooks/lookup_interface_names.yml

+50-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
# Copyright 2018 IBM Corp.
2+
# Copyright 2019 IBM Corp.
33
#
44
# All Rights Reserved.
55
#
@@ -65,4 +65,53 @@
6565
{{ scripts_path }}/python/inv_set_interface_names.py \
6666
{{ item.key }} {{ item.value }} {{ config_path }}"
6767
with_dict: "{{ set_macs_all }}"
68+
69+
- name: Disable any ifcfg scripts that will become stale after renames
70+
hosts: client_nodes
71+
gather_facts: True
72+
vars:
73+
stale_devs: []
74+
tasks:
75+
- block:
76+
- name: Create list of PXE devices that will be renamed
77+
set_fact:
78+
stale_devs: "{{ stale_devs + [mac_to_device[item.0|lower]] }}"
79+
with_together:
80+
- "{{ vars['pxe']['macs'] }}"
81+
- "{{ vars['pxe']['rename'] }}"
82+
- "{{ vars['pxe']['devices'] }}"
83+
when:
84+
- item.0 is not none
85+
- item.1
86+
- item.2 != mac_to_device[item.0|lower]
87+
88+
- name: Create list of Data devices that will be renamed
89+
set_fact:
90+
stale_devs: "{{ stale_devs + [mac_to_device[item.0|lower]] }}"
91+
with_together:
92+
- "{{ vars['data']['macs'] }}"
93+
- "{{ vars['data']['rename'] }}"
94+
- "{{ vars['data']['devices'] }}"
95+
when:
96+
- item.0 is not none
97+
- item.1
98+
- item.2 != mac_to_device[item.0|lower]
99+
100+
- name: Find all interface configuration scripts
101+
find:
102+
paths: /etc/sysconfig/network-scripts/
103+
patterns: 'ifcfg-*'
104+
register: ifcfg_scripts
105+
106+
- name: Disable any interface scripts that will become stale
107+
lineinfile:
108+
path: "{{ item.path }}"
109+
regexp: '^ONBOOT='
110+
line: 'ONBOOT=no # Disabled by POWER-Up'
111+
when:
112+
- (item.path | basename).split('-')[1] != 'lo'
113+
- (item.path | basename).split('-')[1] in stale_devs
114+
loop: "{{ ifcfg_scripts.files }}"
115+
when: (ansible_distribution == 'CentOS' or
116+
ansible_distribution == 'RedHat')
68117
...

playbooks/tasks/create_interfaces.yml

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
# Copyright 2018 IBM Corp.
2+
# Copyright 2019 IBM Corp.
33
#
44
# All Rights Reserved.
55
#
@@ -72,22 +72,4 @@
7272
when: ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat'
7373
with_items: "{{ interfaces }}"
7474

75-
- name: Find all interface configuration scripts
76-
find:
77-
paths: /etc/sysconfig/network-scripts/
78-
patterns: 'ifcfg-*'
79-
register: ifcfg_scripts
80-
81-
- name: Disable any interfaces not defined in inventory
82-
lineinfile:
83-
path: "{{ item.path }}"
84-
regexp: '^ONBOOT='
85-
line: 'ONBOOT=no # Disabled by POWER-Up'
86-
when:
87-
- ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat'
88-
- (item.path | basename).split('-')[1] != 'lo'
89-
- (item.path | basename).split('-')[1] not in pxe.devices
90-
- (item.path | basename).split('-')[1] not in data.devices
91-
loop: "{{ ifcfg_scripts.files }}"
92-
9375
...

0 commit comments

Comments
 (0)