From a8c794e7710b4defb7572bd61a487fe8a44677d2 Mon Sep 17 00:00:00 2001 From: vcandapp Date: Mon, 5 Aug 2024 18:11:39 +0530 Subject: [PATCH] Fail edpm_network_config when there are schema errors Currently when there are schema errors in os-net-config, the logs are updated and no failure happens. Updating this behaviour so that user can fix errors and re-run role --- plugins/modules/edpm_os_net_config.py | 9 +++++++- roles/edpm_network_config/tasks/main.yml | 26 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/plugins/modules/edpm_os_net_config.py b/plugins/modules/edpm_os_net_config.py index 757d7c959..96eecb566 100644 --- a/plugins/modules/edpm_os_net_config.py +++ b/plugins/modules/edpm_os_net_config.py @@ -117,6 +117,8 @@ def _run_os_net_config(config_file, cleanup=False, debug=False, argv.append('--provider nmstate') else: argv.append('--provider ifcfg') + # Force exit on SCHEMA validation errors + argv.append('--exit-on-validation-errors') cmd = " ".join(argv) # Apply the provided network configuration @@ -207,7 +209,7 @@ def main(): detailed_exit_codes = args['detailed_exit_codes'] safe_defaults = args['safe_defaults'] use_nmsate = args['use_nmstate'] - return_codes = [0] + return_codes = [0, 1] if detailed_exit_codes: return_codes.append(2) @@ -230,6 +232,11 @@ def main(): # an operator to ssh the node and debug if needed. _apply_safe_defaults(debug, module.check_mode, use_nmstate=use_nmsate) + elif run.returncode == 1: + results['failed'] = True + results['rc'] = run.returncode + results['msg'] = ("%s failed due to invalid schema, return %s." % ( + cmd, run.returncode)) else: results['rc'] = 0 results['msg'] = ("Successfully run %s." % cmd) diff --git a/roles/edpm_network_config/tasks/main.yml b/roles/edpm_network_config/tasks/main.yml index 71b79971c..7a9f42903 100644 --- a/roles/edpm_network_config/tasks/main.yml +++ b/roles/edpm_network_config/tasks/main.yml @@ -36,7 +36,25 @@ - name: Load system-roles.network tasks [nmstate] ansible.builtin.include_role: name: "{{ lookup('ansible.builtin.env', 'EDPM_SYSTEMROLES', default='fedora.linux_system_roles') + '.network' }}" -- name: Load edpm_network_config tasks [os-net-config] - ansible.builtin.include_tasks: - file: network_config.yml - when: edpm_network_config_tool == 'os-net-config' + +- name: Disable auto-configuration of all interfaces by NetworkManager + when: ( edpm_bootstrap_network_service == 'NetworkManager' ) and + ( edpm_network_config_tool == 'os-net-config' ) + become: true + block: + - name: Set 'no-auto-default' in /etc/NetworkManager/NetworkManager.conf + community.general.ini_file: + path: /etc/NetworkManager/NetworkManager.conf + state: present + no_extra_spaces: true + section: main + option: no-auto-default + value: "*" + backup: true + - name: Restart NetworkManager + ansible.builtin.systemd: + name: NetworkManager + state: restarted + - name: Load edpm_network_config tasks for os-net-config + ansible.builtin.include_tasks: + file: network_config.yml