diff --git a/playbooks/migration_netowrk.yml b/playbooks/migration_netowrk.yml new file mode 100644 index 000000000..fd67fb544 --- /dev/null +++ b/playbooks/migration_netowrk.yml @@ -0,0 +1,23 @@ +--- + +- name: Migrate EDPM Network + hosts: "{{ edpm_override_hosts | default('all', true) }}" + strategy: linear + gather_facts: "{{ gather_facts | default(false) }}" + any_errors_fatal: "{{ edpm_any_errors_fatal | default(true) }}" + max_fail_percentage: "{{ edpm_max_fail_percentage | default(0) }}" + tasks: + # Purge EDPM network using os-net-config + - name: Purge edpm_network_config + ansible.builtin.import_role: + name: osp.edpm.edpm_network_config + tasks_from: purge_os_net_config.yml + tags: + - edpm_purge_network_config + + # Sets up EDPM network using os-net-config + - name: Import edpm_network_config + ansible.builtin.import_role: + name: osp.edpm.edpm_network_config + tags: + - edpm_network_config diff --git a/plugins/modules/edpm_os_net_config.py b/plugins/modules/edpm_os_net_config.py index 4bac2bf8c..8a54eee5a 100644 --- a/plugins/modules/edpm_os_net_config.py +++ b/plugins/modules/edpm_os_net_config.py @@ -72,6 +72,12 @@ - If enabled, use nmstate and network manager for network configuration. type: bool default: false + purge_provider: + description: + - purge provider to cleanup existing network configuration. + type: str + default: '' + """ EXAMPLES = """ @@ -102,7 +108,7 @@ def _run_os_net_config(config_file, cleanup=False, debug=False, detailed_exit_codes=False, noop=False, - use_nmstate=False): + use_nmstate=False, purge_provider=''): # Build os-net-config command argv = ['os-net-config --config-file {}'.format(config_file)] if cleanup: @@ -117,6 +123,9 @@ def _run_os_net_config(config_file, cleanup=False, debug=False, argv.append('--provider nmstate') else: argv.append('--provider ifcfg') + if len(purge_provider) > 0: + argv.append('--purge_provider {}'.format(purge_provider)) + cmd = " ".join(argv) # Apply the provided network configuration @@ -206,6 +215,10 @@ def main(): detailed_exit_codes = args['detailed_exit_codes'] safe_defaults = args['safe_defaults'] use_nmsate = args['use_nmstate'] + if len(args['purge_provider']) > 0: + purge_provider = args['purge_provider'] + else: + purge_provider = '' return_codes = [0] if detailed_exit_codes: return_codes.append(2) @@ -214,7 +227,8 @@ def main(): cmd, run = _run_os_net_config(config_file, cleanup, debug, detailed_exit_codes, module.check_mode, - use_nmstate=use_nmsate) + use_nmstate=use_nmsate, + purge_provider=purge_provider) results['stderr'] = run.stderr results['stdout'] = run.stdout if run.returncode not in return_codes and not module.check_mode: diff --git a/roles/edpm_network_config/defaults/main.yml b/roles/edpm_network_config/defaults/main.yml index 69a01f11e..a4e53cec7 100644 --- a/roles/edpm_network_config/defaults/main.yml +++ b/roles/edpm_network_config/defaults/main.yml @@ -49,6 +49,7 @@ edpm_network_config_hide_sensitive_logs: true edpm_network_config_interface_name: nic1 edpm_network_config_manage_service: true edpm_network_config_nmstate: true +edpm_network_config_purge_provider: "ifcfg" edpm_network_config_os_net_config_mappings: {} edpm_network_config_safe_defaults: false edpm_network_config_template: "" diff --git a/roles/edpm_network_config/meta/argument_specs.yml b/roles/edpm_network_config/meta/argument_specs.yml index b879391e2..f43279eb2 100644 --- a/roles/edpm_network_config/meta/argument_specs.yml +++ b/roles/edpm_network_config/meta/argument_specs.yml @@ -57,6 +57,10 @@ argument_specs: type: dict description: "Per node and/or per node group configuration map. Used by the edpm_os_net_config_mappings module." default: {} + edpm_network_config_purge_provider: + type: str + description: "os-net-config purge provider to cleanup exisiting network configurations " + default: "ifcfg" edpm_network_config_safe_defaults: type: bool description: > diff --git a/roles/edpm_network_config/tasks/purge_os_net_config.yml b/roles/edpm_network_config/tasks/purge_os_net_config.yml new file mode 100644 index 000000000..b8bbf81af --- /dev/null +++ b/roles/edpm_network_config/tasks/purge_os_net_config.yml @@ -0,0 +1,54 @@ +--- +# Copyright 2020 Red Hat, Inc. +# 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. +# +# Apply network configuration with os-net-config. +# + +- name: Purge os-net-config configuration + become: true + block: + - name: Set nic_config_file fact + ansible.builtin.set_fact: + nic_config_file: "/etc/os-net-config/config.yaml" + - name: Render network_config from template + no_log: "{{ edpm_network_config_hide_sensitive_logs | bool }}" + ansible.builtin.copy: + content: "{{ edpm_network_config_template }}" + dest: "{{ nic_config_file }}" + mode: '0644' + backup: true + - name: Retrieve and output nic_config_file contents for debug before applying + when: edpm_network_config_debug|bool + block: + - name: Retrieve content of nic_config_file before applying + ansible.builtin.slurp: + path: "{{ nic_config_file }}" + register: os_net_config_config + - name: Debug print nic_config_file contents + ansible.builtin.debug: + msg: "{{ os_net_config_config['content'] | b64decode | trim }}" + - name: Run edpm_os_net_config_module to purge network_config + edpm_os_net_config: + cleanup: "{{ edpm_network_config_nonconfigured_cleanup }}" + config_file: "{{ nic_config_file }}" + purge-provider: "{{ edpm_network_config_purge_provider }}" + debug: "{{ edpm_network_config_debug | bool }}" + detailed_exit_codes: true + safe_defaults: "{{ edpm_network_config_safe_defaults | bool }}" + async: "{{ edpm_network_config_async_timeout }}" + poll: "{{ edpm_network_config_async_poll }}" + register: network_config_result + when: not ansible_check_mode