Repository: ansible/ansible

Issue:
nxos_mtu: UnboundLocalError: local variable 'body' referenced before assignment
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
nxos_mtu

##### ANSIBLE VERSION
```
5cccb7a5d7b027b412037a71b92ec2c7f8033af9
```


##### SUMMARY
https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/network/nxos/nxos_mtu.py#L125-L134

Is failing as `module.params['transport']` is `None`.

load_provider for NXOS is the same as eos https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/action/nxos.py#L115-L125

Though this section is only in `nxos` https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/action/nxos.py#L101-L105


##### STEPS TO REPRODUCE
```yaml
- name: configure system mtu 
  nxos_mtu:
    sysmtu: 2000
    provider: "{{ cli }}"
  register: result
```


##### EXPECTED RESULTS

##### ACTUAL RESULTS
Line numbers may not match as I've been adding debug, it is actually https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/network/nxos/nxos_mtu.py#L125-L134
```yaml
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_RepKc7/ansible_module_nxos_mtu.py", line 382, in <module>
    main()
  File "/tmp/ansible_RepKc7/ansible_module_nxos_mtu.py", line 311, in main
    existing = get_system_mtu(module)
  File "/tmp/ansible_RepKc7/ansible_module_nxos_mtu.py", line 172, in get_system_mtu
    body = execute_show_command(command, module, command_type='cli_show_ascii')
  File "/tmp/ansible_RepKc7/ansible_module_nxos_mtu.py", line 137, in execute_show_command
    return body
UnboundLocalError: local variable 'body' referenced before assignment

fatal: [nxos01]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_RepKc7/ansible_module_nxos_mtu.py\", line 382, in <module>\n    main()\n  File \"/tmp/ansible_RepKc7/ansible_module_nxos_mtu.py\", line 311, in main\n    existing = get_system_mtu(module)\n  File \"/tmp/ansible_RepKc7/ansible_module_nxos_mtu.py\", line 172, in get_system_mtu\n    body = execute_show_command(command, module, command_type='cli_show_ascii')\n  File \"/tmp/ansible_RepKc7/ansible_module_nxos_mtu.py\", line 137, in execute_show_command\n    return body\nUnboundLocalError: local variable 'body' referenced before assignment\n", 
    "module_stdout": "None\n", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

```



Discussion:
I've put this as a P2 as a workaround exists, which is to specify transport (rather than use the version contained within `provider`
`    transport: nxapi`
cc @rcarrillocruz @privateip @Qalthos
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @jedelman8 @GGabriele
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/plugins/action/nxos.py b/lib/ansible/plugins/action/nxos.py
--- a/lib/ansible/plugins/action/nxos.py
+++ b/lib/ansible/plugins/action/nxos.py
@@ -99,10 +99,7 @@ def run(self, tmp=None, task_vars=None):
             self._task.args['provider'] = provider_arg
 
         # make sure a transport value is set in args
-        transport = self._task.args.get('transport')
-        provider_transport = (self._task.args.get('provider') or {}).get('transport')
-        if all((transport is None, provider_transport is None)):
-            self._task.args['transport'] = 'cli'
+        self._task.args['transport'] = transport
 
         return super(ActionModule, self).run(tmp, task_vars)
 


Test patch: