Repository: ansible/ansible

Issue:
Parameter provider is required in module nxos_vrf
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report


##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
nxos_vrf

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ubuntu@ubuntu-xenial:/vagrant/ansible-nxos$ ansible --version
ansible 2.3.0.0
  config file = /vagrant/ansible-nxos/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
ubuntu@ubuntu-xenial:/vagrant/ansible-nxos$
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->
Ubuntu

##### SUMMARY
<!--- Explain the problem briefly -->

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml

The following playbook produces error
  tasks: 
    - name: Create vrfs
      nxos_vrf:
        vrf: test-vrf

This is working properly
  vars:
    prov:        
      transport: cli
  
  tasks: 
    - name: Create vrfs
      nxos_vrf:
        vrf: test-vrf
        provider: "{{ prov }}"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
ubuntu@ubuntu-xenial:/vagrant/ansible-nxos$ ansible-playbook -i hosts test1.yml -u cisco -k
SSH password:

PLAY [vlan testing] ************************************************************************************************************************************************************************************************************************************************


TASK [Create vrfs] *************************************************************************************************************************************************************************************************************************************************

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: 'NoneType' object has no attribute '__getitem__'
fatal: [sp2]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_BBb2AR/ansible_module_nxos_vrf.py\", line 326, in <module>\n    main()\n  File \"/tmp/ansible_BBb2AR/ansible_module_nxos_vrf
.py\", line 269, in main\n    existing = get_vrf(vrf, module)\n  File \"/tmp/ansible_BBb2AR/ansible_module_nxos_vrf.py\", line 215, in get_vrf\n    body = execute_show_command(command, module)\n  File \"/tmp/ansible_BBb2AR/ansible_module_nxos_vrf.py\", line 12
9, in execute_show_command\n    transport = module.params['provider']['transport']\nTypeError: 'NoneType' object has no attribute '__getitem__'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: 'NoneType' object has no attribute '__getitem__'
fatal: [sp1]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_4Mqx2r/ansible_module_nxos_vrf.py\", line 326, in <module>\n    main()\n  File \"/tmp/ansible_4Mqx2r/ansible_module_nxos_vrf
.py\", line 269, in main\n    existing = get_vrf(vrf, module)\n  File \"/tmp/ansible_4Mqx2r/ansible_module_nxos_vrf.py\", line 215, in get_vrf\n    body = execute_show_command(command, module)\n  File \"/tmp/ansible_4Mqx2r/ansible_module_nxos_vrf.py\", line 12
9, in execute_show_command\n    transport = module.params['provider']['transport']\nTypeError: 'NoneType' object has no attribute '__getitem__'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
        to retry, use: --limit @/vagrant/ansible-nxos/test1.retry

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************

sp1                        : ok=0    changed=0    unreachable=0    failed=1
sp2                        : ok=0    changed=0    unreachable=0    failed=1

--------

It looks like although provider is an optional parameter, it is required in configuration because of line 129 in source code.


```



Discussion:
cc @jedelman8 @GGabriele @rahushen @privateip @rcarrillocruz
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @mikewiebe
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/network/nxos/nxos_vrf.py b/lib/ansible/modules/network/nxos/nxos_vrf.py
--- a/lib/ansible/modules/network/nxos/nxos_vrf.py
+++ b/lib/ansible/modules/network/nxos/nxos_vrf.py
@@ -125,16 +125,15 @@
 from ansible.module_utils.nxos import nxos_argument_spec, check_args
 from ansible.module_utils.basic import AnsibleModule
 
-def execute_show_command(command, module, command_type='cli_show'):
-    transport = module.params['provider']['transport']
-    if transport in ['cli', None]:
+
+def execute_show_command(command, module):
+    transport = module.params['transport']
+    if transport == 'cli':
         if 'show run' not in command:
             command += ' | json'
-        cmds = [command]
-        body = run_commands(module, cmds)
-    else:
-        cmds = [command]
-        body = run_commands(module, cmds)
+
+    cmds = [command]
+    body = run_commands(module, cmds)
     return body
 
 
@@ -174,12 +173,11 @@ def get_commands_to_config_vrf(delta, vrf):
 
 
 def get_vrf_description(vrf, module):
-    command_type = 'cli_show_ascii'
     command = (r'show run section vrf | begin ^vrf\scontext\s{0} | end ^vrf.*'.format(vrf))
 
     description = ''
     descr_regex = r".*description\s(?P<descr>[\S+\s]+).*"
-    body = execute_show_command(command, module, command_type)
+    body = execute_show_command(command, module)
 
     try:
         body = body[0]
@@ -221,7 +219,7 @@ def get_vrf(vrf, module):
     parsed_vrf = apply_key_map(vrf_key, vrf_table)
 
     command = 'show run all | section vrf.context.{0}'.format(vrf)
-    body = execute_show_command(command, module, 'cli_show_ascii')
+    body = execute_show_command(command, module)
     extra_params = ['vni', 'rd', 'description']
     for param in extra_params:
         parsed_vrf[param] = get_value(param, body[0], module)


Test patch: