diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py index d3ce6d28be5..2086781c1ec 100644 --- a/lib/ansible/module_utils/nxos.py +++ b/lib/ansible/module_utils/nxos.py @@ -49,6 +49,7 @@ nxos_provider_spec = { 'use_ssl': dict(type='bool'), 'validate_certs': dict(type='bool'), + 'timeout': dict(type='int'), 'transport': dict(default='cli', choices=['cli', 'nxapi']) @@ -68,7 +69,7 @@ nxos_top_spec = { 'validate_certs': dict(removed_in_version=2.9, type='bool'), 'timeout': dict(removed_in_version=2.9, type='int'), - 'transport': dict(removed_in_version=2.9, default='cli', choices=['cli', 'nxapi']) + 'transport': dict(removed_in_version=2.9, choices=['cli', 'nxapi']) } nxos_argument_spec.update(nxos_top_spec) @@ -84,7 +85,7 @@ def check_args(module, warnings): def load_params(module): provider = module.params.get('provider') or dict() for key, value in iteritems(provider): - if key in nxos_argument_spec: + if key in nxos_provider_spec: if module.params.get(key) is None and value is not None: module.params[key] = value diff --git a/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py b/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py index 03dd134c6ec..eb5ab6b2afd 100644 --- a/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py +++ b/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py @@ -161,12 +161,13 @@ from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module, command_type='cli_show'): - if module.params['transport'] == 'cli': + provider = module.params['provider'] + if provider['transport'] == 'cli': if 'show run' not in command: command += ' | json' cmds = [command] body = run_commands(module, cmds) - elif module.params['transport'] == 'nxapi': + elif provider['transport'] == 'nxapi': cmds = {'command': command, 'output': 'text'} body = run_commands(module, cmds) diff --git a/lib/ansible/modules/network/nxos/nxos_gir.py b/lib/ansible/modules/network/nxos/nxos_gir.py index e7cf944c747..1ead82a336d 100644 --- a/lib/ansible/modules/network/nxos/nxos_gir.py +++ b/lib/ansible/modules/network/nxos/nxos_gir.py @@ -170,9 +170,10 @@ from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module, command_type='cli_show_ascii'): cmds = [command] - if module.params['transport'] == 'cli': + provider = module.params['provider'] + if provider['transport'] == 'cli': body = run_commands(module, cmds) - elif module.params['transport'] == 'nxapi': + elif provider['transport'] == 'nxapi': body = run_commands(module, cmds) return body diff --git a/lib/ansible/modules/network/nxos/nxos_hsrp.py b/lib/ansible/modules/network/nxos/nxos_hsrp.py index 9e99be0156f..7375a9ebd26 100644 --- a/lib/ansible/modules/network/nxos/nxos_hsrp.py +++ b/lib/ansible/modules/network/nxos/nxos_hsrp.py @@ -129,11 +129,12 @@ from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module): - if module.params['transport'] == 'cli': + provider = module.params['provider'] + if provider['transport'] == 'cli': command += ' | json' cmds = [command] body = run_commands(module, cmds) - elif module.params['transport'] == 'nxapi': + elif provider['transport'] == 'nxapi': cmds = [command] body = run_commands(module, cmds) @@ -394,7 +395,7 @@ def main(): auth_type = module.params['auth_type'] auth_string = module.params['auth_string'] - transport = module.params['transport'] + transport = module.params['provider']['transport'] if state == 'present' and not vip: module.fail_json(msg='the "vip" param is required when state=present') diff --git a/lib/ansible/modules/network/nxos/nxos_ip_interface.py b/lib/ansible/modules/network/nxos/nxos_ip_interface.py index c30bc9d25d1..065ee9d16bb 100644 --- a/lib/ansible/modules/network/nxos/nxos_ip_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_ip_interface.py @@ -425,7 +425,7 @@ def validate_params(addr, interface, mask, tag, allow_secondary, version, state, module.fail_json(msg="IPv6 address and mask must be provided when " "state=absent.") - if intf_type != "ethernet" and module.params["transport"] == "cli": + if intf_type != "ethernet" and module.params["provider"]["transport"] == "cli": if is_default(interface, module) == "DNE": module.fail_json(msg="That interface does not exist yet. Create " "it first.", interface=interface) diff --git a/lib/ansible/modules/network/nxos/nxos_nxapi.py b/lib/ansible/modules/network/nxos/nxos_nxapi.py index 9b24e8b9156..de1bd7d7d16 100644 --- a/lib/ansible/modules/network/nxos/nxos_nxapi.py +++ b/lib/ansible/modules/network/nxos/nxos_nxapi.py @@ -131,10 +131,9 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six import iteritems def check_args(module, warnings): - transport = module.params['transport'] - provider_transport = (module.params['provider'] or {}).get('transport') - if 'nxapi' in (transport, provider_transport): - module.fail_json(msg='transport=nxapi is not supporting when configuring nxapi') + provider = module.params['provider'] + if provider['transport'] == 'nxapi': + module.fail_json(msg='module not supported over nxapi transport') nxos_check_args(module, warnings) @@ -149,9 +148,6 @@ def check_args(module, warnings): warnings.append('state=stopped is deprecated and will be removed in a ' 'a future release. Please use state=absent instead') - if module.params['transport'] == 'nxapi': - module.fail_json(msg='module not supported over nxapi transport') - for key in ['config']: if module.params[key]: warnings.append('argument %s is deprecated and will be ignored' % key) diff --git a/lib/ansible/modules/network/nxos/nxos_portchannel.py b/lib/ansible/modules/network/nxos/nxos_portchannel.py index 5602aa21282..9bf8b86300b 100644 --- a/lib/ansible/modules/network/nxos/nxos_portchannel.py +++ b/lib/ansible/modules/network/nxos/nxos_portchannel.py @@ -142,12 +142,13 @@ def get_custom_value(arg, config, module): def execute_show_command(command, module): - if module.params['transport'] == 'cli': + provider = module.params['provider'] + if provider['transport'] == 'cli': if 'show port-channel summary' in command: command += ' | json' cmds = [command] body = run_commands(module, cmds) - elif module.params['transport'] == 'nxapi': + elif provider['transport'] == 'nxapi': cmds = [command] body = run_commands(module, cmds) diff --git a/lib/ansible/modules/network/nxos/nxos_switchport.py b/lib/ansible/modules/network/nxos/nxos_switchport.py index b5658c78884..969e2b11b25 100644 --- a/lib/ansible/modules/network/nxos/nxos_switchport.py +++ b/lib/ansible/modules/network/nxos/nxos_switchport.py @@ -434,11 +434,12 @@ def apply_value_map(value_map, resource): def execute_show_command(command, module, command_type='cli_show'): - if module.params['transport'] == 'cli': + provider = module.params['provider'] + if provider['transport'] == 'cli': command += ' | json' cmds = [command] body = run_commands(module, cmds) - elif module.params['transport'] == 'nxapi': + elif provider['transport'] == 'nxapi': cmds = [command] body = run_commands(module, cmds) diff --git a/lib/ansible/modules/network/nxos/nxos_udld.py b/lib/ansible/modules/network/nxos/nxos_udld.py index fa3aeec7677..fce27c728cc 100644 --- a/lib/ansible/modules/network/nxos/nxos_udld.py +++ b/lib/ansible/modules/network/nxos/nxos_udld.py @@ -121,12 +121,13 @@ import re def execute_show_command(command, module, command_type='cli_show'): - if module.params['transport'] == 'cli': + provider = module.params['provider'] + if provider['transport'] == 'cli': if 'show run' not in command: command += ' | json' cmds = [command] body = run_commands(module, cmds) - elif module.params['transport'] == 'nxapi': + elif provider['transport'] == 'nxapi': cmds = [command] body = run_commands(module, cmds) diff --git a/lib/ansible/modules/network/nxos/nxos_udld_interface.py b/lib/ansible/modules/network/nxos/nxos_udld_interface.py index 9e83a93b09d..116b8b4ee64 100644 --- a/lib/ansible/modules/network/nxos/nxos_udld_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_udld_interface.py @@ -116,12 +116,13 @@ from ansible.module_utils.basic import AnsibleModule def execute_show_command(command, module, command_type='cli_show'): - if module.params['transport'] == 'cli': + provider = module.params['provider'] + if provider['transport'] == 'cli': if 'show run' not in command: command += ' | json' cmds = [command] body = run_commands(module, cmds) - elif module.params['transport'] == 'nxapi': + elif provider['transport'] == 'nxapi': cmds = [command] body = run_commands(module, cmds) diff --git a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py index ac3c200104b..33ca1df77da 100644 --- a/lib/ansible/modules/network/nxos/nxos_vrf_interface.py +++ b/lib/ansible/modules/network/nxos/nxos_vrf_interface.py @@ -204,7 +204,7 @@ def main(): "Use nxos_vrf to fix this.") intf_type = get_interface_type(interface) - if (intf_type != 'ethernet' and module.params['transport'] == 'cli'): + if (intf_type != 'ethernet' and module.params['provider']['transport'] == 'cli'): if is_default(interface, module) == 'DNE': module.fail_json(msg="interface does not exist on switch. Verify " "switch platform or create it first with " diff --git a/lib/ansible/plugins/action/nxos.py b/lib/ansible/plugins/action/nxos.py index b1feccfd28f..10e08e4aa9d 100644 --- a/lib/ansible/plugins/action/nxos.py +++ b/lib/ansible/plugins/action/nxos.py @@ -107,8 +107,5 @@ class ActionModule(_ActionModule): self._task.args['provider'] = provider - # make sure a transport value is set in args - self._task.args['transport'] = transport - result = super(ActionModule, self).run(tmp, task_vars) return result diff --git a/test/units/modules/network/nxos/nxos_module.py b/test/units/modules/network/nxos/nxos_module.py index 77b5785b7e3..a9546f84483 100644 --- a/test/units/modules/network/nxos/nxos_module.py +++ b/test/units/modules/network/nxos/nxos_module.py @@ -29,6 +29,9 @@ from ansible.module_utils._text import to_bytes def set_module_args(args): + if 'provider' not in args: + args['provider'] = {'transport': args.get('transport') or 'cli'} + args = json.dumps({'ANSIBLE_MODULE_ARGS': args}) basic._ANSIBLE_ARGS = to_bytes(args)