From 58ade65ea6865527e04e2e4d90ecdcec814c67f0 Mon Sep 17 00:00:00 2001 From: James Mighion Date: Mon, 10 Jul 2017 09:22:45 -0700 Subject: [PATCH] Adding admin option for iosxr_config (#26509) * Adding admin option for iosxr_config. Adding unit test for new admin option for iosxr_config. Fixes #24308 * Removing space on empty line. --- lib/ansible/module_utils/iosxr.py | 8 ++++++-- lib/ansible/modules/network/iosxr/iosxr_config.py | 12 +++++++++++- .../units/modules/network/iosxr/test_iosxr_config.py | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/iosxr.py b/lib/ansible/module_utils/iosxr.py index 08e58827fd6..3b5ba54b287 100644 --- a/lib/ansible/module_utils/iosxr.py +++ b/lib/ansible/module_utils/iosxr.py @@ -102,9 +102,12 @@ def run_commands(module, commands, check_rc=True): return responses -def load_config(module, commands, warnings, commit=False, replace=False, comment=None): +def load_config(module, commands, warnings, commit=False, replace=False, comment=None, admin=False): + cmd = 'configure terminal' + if admin: + cmd = 'admin ' + cmd - rc, out, err = exec_command(module, 'configure terminal') + rc, out, err = exec_command(module, cmd) if rc != 0: module.fail_json(msg='unable to enter configuration mode', err=to_text(err, errors='surrogate_or_strict')) @@ -137,6 +140,7 @@ def load_config(module, commands, warnings, commit=False, replace=False, comment else: cmd = 'abort' diff = None + rc, out, err = exec_command(module, cmd) if rc != 0: exec_command(module, 'abort') diff --git a/lib/ansible/modules/network/iosxr/iosxr_config.py b/lib/ansible/modules/network/iosxr/iosxr_config.py index 125b7d2e7d6..6de819c5d61 100644 --- a/lib/ansible/modules/network/iosxr/iosxr_config.py +++ b/lib/ansible/modules/network/iosxr/iosxr_config.py @@ -146,6 +146,14 @@ options: required: false default: 'configured by iosxr_config' version_added: "2.2" + admin: + description: + - Enters into administration configuration mode for making config + changes to the device. + required: false + default: false + choices: [ "yes", "no" ] + version_added: "2.4" """ EXAMPLES = """ @@ -218,6 +226,7 @@ def run(module, result): replace_config = replace == 'config' path = module.params['parents'] comment = module.params['comment'] + admin = module.params['admin'] check_mode = module.check_mode candidate = get_candidate(module) @@ -243,7 +252,7 @@ def run(module, result): result['commands'] = commands diff = load_config(module, commands, result['warnings'], - not check_mode, replace_config, comment) + not check_mode, replace_config, comment, admin) if diff: result['diff'] = dict(prepared=diff) result['changed'] = True @@ -270,6 +279,7 @@ def main(): config=dict(), backup=dict(type='bool', default=False), comment=dict(default=DEFAULT_COMMIT_COMMENT), + admin=dict(type='bool', default=False) ) argument_spec.update(iosxr_argument_spec) diff --git a/test/units/modules/network/iosxr/test_iosxr_config.py b/test/units/modules/network/iosxr/test_iosxr_config.py index d10f3e21df3..5e2f696e3a0 100644 --- a/test/units/modules/network/iosxr/test_iosxr_config.py +++ b/test/units/modules/network/iosxr/test_iosxr_config.py @@ -107,6 +107,11 @@ class TestIosxrConfigModule(TestIosxrModule): set_module_args(dict(lines=lines, force=True)) self.execute_module(changed=True, commands=lines) + def test_iosxr_config_admin(self): + lines = ['username admin', 'group root-system', 'secret P@ssw0rd'] + set_module_args(dict(lines=lines, admin=True)) + self.execute_module(changed=True, commands=lines) + def test_iosxr_config_match_none(self): lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string'] parents = ['interface GigabitEthernet0/0']