Skip to content

Commit cec919c

Browse files
author
Jaganathan Palanisamy
committed
Network Configs Migration ifcfg to nmstate provider
This changes to migrate the os-net-config provuder ifcfg to nmstate.
1 parent 86becb1 commit cec919c

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

playbooks/migration_netowrk.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
3+
- name: Purgey EDPM Network
4+
hosts: "{{ edpm_override_hosts | default('all', true) }}"
5+
strategy: linear
6+
gather_facts: "{{ gather_facts | default(false) }}"
7+
any_errors_fatal: "{{ edpm_any_errors_fatal | default(true) }}"
8+
max_fail_percentage: "{{ edpm_max_fail_percentage | default(0) }}"
9+
tasks:
10+
# Purge EDPM network using os-net-config
11+
- name: Purge edpm_network_config
12+
ansible.builtin.import_role:
13+
name: osp.edpm.edpm_network_config
14+
tasks_from: purge_os-net-config.yml
15+
tags:
16+
- edpm_purge_network_config
17+
18+
# Sets up EDPM network using os-net-config
19+
- name: Import edpm_network_config
20+
ansible.builtin.import_role:
21+
name: osp.edpm.edpm_network_config
22+
tags:
23+
- edpm_network_config

plugins/modules/edpm_os_net_config.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
- If enabled, use nmstate and network manager for network configuration.
7373
type: bool
7474
default: false
75+
purge_provider:
76+
description:
77+
- purge provider to cleanup existing network configuration.
78+
type: str
79+
default: ''
80+
7581
"""
7682

7783
EXAMPLES = """
@@ -102,7 +108,7 @@
102108

103109
def _run_os_net_config(config_file, cleanup=False, debug=False,
104110
detailed_exit_codes=False, noop=False,
105-
use_nmstate=False):
111+
use_nmstate=False, purge_provider=''):
106112
# Build os-net-config command
107113
argv = ['os-net-config --config-file {}'.format(config_file)]
108114
if cleanup:
@@ -117,6 +123,9 @@ def _run_os_net_config(config_file, cleanup=False, debug=False,
117123
argv.append('--provider nmstate')
118124
else:
119125
argv.append('--provider ifcfg')
126+
if len(purge_provider) > 0:
127+
argv.append('--purge_provider {}'.format(purge_provider))
128+
120129
cmd = " ".join(argv)
121130

122131
# Apply the provided network configuration
@@ -206,6 +215,10 @@ def main():
206215
detailed_exit_codes = args['detailed_exit_codes']
207216
safe_defaults = args['safe_defaults']
208217
use_nmsate = args['use_nmstate']
218+
if len(args['purge_provider']) > 0:
219+
purge_provider = args['purge_provider']
220+
else:
221+
purge_provider = ''
209222
return_codes = [0]
210223
if detailed_exit_codes:
211224
return_codes.append(2)
@@ -214,7 +227,8 @@ def main():
214227
cmd, run = _run_os_net_config(config_file, cleanup, debug,
215228
detailed_exit_codes,
216229
module.check_mode,
217-
use_nmstate=use_nmsate)
230+
use_nmstate=use_nmsate,
231+
purge_provider=purge_provider)
218232
results['stderr'] = run.stderr
219233
results['stdout'] = run.stdout
220234
if run.returncode not in return_codes and not module.check_mode:

roles/edpm_network_config/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ edpm_network_config_hide_sensitive_logs: true
4949
edpm_network_config_interface_name: nic1
5050
edpm_network_config_manage_service: true
5151
edpm_network_config_nmstate: true
52+
edpm_network_config_purge_provider: "ifcfg"
5253
edpm_network_config_os_net_config_mappings: {}
5354
edpm_network_config_safe_defaults: false
5455
edpm_network_config_template: ""

roles/edpm_network_config/meta/argument_specs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ argument_specs:
5757
type: dict
5858
description: "Per node and/or per node group configuration map. Used by the edpm_os_net_config_mappings module."
5959
default: {}
60+
edpm_network_config_purge_provider:
61+
type: str
62+
description: "os-net-config purge provider to cleanup exisiting network configurations "
63+
default: "ifcfg"
6064
edpm_network_config_safe_defaults:
6165
type: bool
6266
description: >
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
# Copyright 2020 Red Hat, Inc.
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# 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, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
#
17+
# Apply network configuration with os-net-config.
18+
#
19+
20+
- name: Purge os-net-config configuration
21+
become: true
22+
block:
23+
- name: Set nic_config_file fact
24+
ansible.builtin.set_fact:
25+
nic_config_file: "/etc/os-net-config/config.yaml"
26+
- name: Render network_config from template
27+
no_log: "{{ edpm_network_config_hide_sensitive_logs | bool }}"
28+
ansible.builtin.copy:
29+
content: "{{ edpm_network_config_template }}"
30+
dest: "{{ nic_config_file }}"
31+
mode: '0644'
32+
backup: true
33+
- name: Retrieve and output nic_config_file contents for debug before applying
34+
when: edpm_network_config_debug|bool
35+
block:
36+
- name: Retrieve content of nic_config_file before applying
37+
ansible.builtin.slurp:
38+
path: "{{ nic_config_file }}"
39+
register: os_net_config_config
40+
- name: Debug print nic_config_file contents
41+
ansible.builtin.debug:
42+
msg: "{{ os_net_config_config['content'] | b64decode | trim }}"
43+
- name: Run edpm_os_net_config_module to purge network_config
44+
edpm_os_net_config:
45+
cleanup: "{{ edpm_network_config_nonconfigured_cleanup }}"
46+
config_file: "{{ nic_config_file }}"
47+
purge-provider: "{{ edpm_network_config_purge_provider }}"
48+
debug: "{{ edpm_network_config_debug | bool }}"
49+
detailed_exit_codes: true
50+
safe_defaults: "{{ edpm_network_config_safe_defaults | bool }}"
51+
async: "{{ edpm_network_config_async_timeout }}"
52+
poll: "{{ edpm_network_config_async_poll }}"
53+
register: network_config_result
54+
when: not ansible_check_mode

0 commit comments

Comments
 (0)