diff options
Diffstat (limited to 'lib/ansible/modules/network/iosxr/_iosxr_template.py')
-rw-r--r-- | lib/ansible/modules/network/iosxr/_iosxr_template.py | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/lib/ansible/modules/network/iosxr/_iosxr_template.py b/lib/ansible/modules/network/iosxr/_iosxr_template.py index 70a37f228e..a66c49896f 100644 --- a/lib/ansible/modules/network/iosxr/_iosxr_template.py +++ b/lib/ansible/modules/network/iosxr/_iosxr_template.py @@ -106,14 +106,23 @@ responses: type: list sample: ['...', '...'] """ +from ansible.module_utils.local import LocalAnsibleModule from ansible.module_utils.netcfg import NetworkConfig, dumps -from ansible.module_utils.iosxr import NetworkModule +from ansible.module_utils.iosxr import get_config, load_config +from ansible.module_utils.network import NET_TRANSPORT_ARGS, _transitional_argument_spec + + +def check_args(module): + warnings = list() + for key in NET_TRANSPORT_ARGS: + if module.params[key]: + warnings.append( + 'network provider arguments are no longer supported. Please ' + 'use connection: network_cli for the task' + ) + break + return warnings -def get_config(module): - config = module.params['config'] or dict() - if not config and not module.params['force']: - config = module.config.get_config() - return config def main(): """ main entry point for module execution @@ -126,33 +135,37 @@ def main(): config=dict(), ) + # Removed the use of provider arguments in 2.3 due to network_cli + # connection plugin. To be removed in 2.5 + argument_spec.update(_transitional_argument_spec()) + mutually_exclusive = [('config', 'backup'), ('config', 'force')] - module = NetworkModule(argument_spec=argument_spec, + module = LocalAnsibleModule(argument_spec=argument_spec, mutually_exclusive=mutually_exclusive, supports_check_mode=True) - result = dict(changed=False) + warnings = check_args(module) + + result = dict(changed=False, warnings=warnings) candidate = NetworkConfig(contents=module.params['src'], indent=1) - contents = get_config(module) - if contents: - config = NetworkConfig(contents=contents, indent=1) - result['_backup'] = str(contents) + if module.params['backup']: + result['__backup__'] = get_config(module) if not module.params['force']: - commands = candidate.difference(config) + contents = get_config(module) + configobj = NetworkConfig(contents=contents, indent=1) + commands = candidate.difference(configobj) commands = dumps(commands, 'commands').split('\n') - commands = [str(c) for c in commands if c] + commands = [str(c).strip() for c in commands if c] else: - commands = str(candidate).split('\n') + commands = [c.strip() for c in str(candidate).split('\n')] if commands: - if not module.check_mode: - response = module.config(commands) - result['responses'] = response - result['changed'] = True + load_config(module, commands, not module.check_mode) + result['changed'] = not module.check_mode result['updates'] = commands module.exit_json(**result) |