Repository: ansible/ansible

Issue:
module_utils/nxos.py: NameError: global name 'commands' is not defined
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
nxos_

##### ANSIBLE VERSION
```
ansible 2.3.0 (devel d0278d1d1e) last updated 2017/02/24 13:43:19 (GMT +100)
```


##### SUMMARY
```
⚠     def load_config(self, config):
          """Sends the ordered set of commands to the device
          """
          cmds = ['configure terminal']
✗         cmds.extend(commands)
✗         self.send_request(commands, output='config')
```


##### STEPS TO REPRODUCE
```yaml
- name: setup
  nxos_config:
    commands:
      - no description
      - no shutdown
    parents:
      - interface Ethernet2/5
    match: none
    provider: "{{ nxapi }}"

```


##### EXPECTED RESULTS

##### ACTUAL RESULTS
```yaml
 [WARNING]: Removed unexpected internal key in module return: _ansible_parsed = False

An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_OXNKEe/ansible_module_nxos_config.py", line 343, in <module>
    main()
  File "/tmp/ansible_OXNKEe/ansible_module_nxos_config.py", line 331, in main
    run(module, result)
  File "/tmp/ansible_OXNKEe/ansible_module_nxos_config.py", line 276, in run
    load_config(module, commands)
  File "/tmp/ansible_OXNKEe/ansible_modlib.zip/ansible/module_utils/nxos.py", line 358, in load_config
  File "/tmp/ansible_OXNKEe/ansible_modlib.zip/ansible/module_utils/nxos.py", line 313, in load_config
NameError: global name 'commands' is not defined

fatal: [nxos01]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_OXNKEe/ansible_module_nxos_config.py\", line 343, in <module>\n    main()\n  File \"/tmp/ansible_OXNKEe/ansible_module_nxos_config.py\", line 331, in main\n    run(module, result)\n  File \"/tmp/ansible_OXNKEe/ansible_module_nxos_config.py\", line 276, in run\n    load_config(module, commands)\n  File \"/tmp/ansible_OXNKEe/ansible_modlib.zip/ansible/module_utils/nxos.py\", line 358, in load_config\n  File \"/tmp/ansible_OXNKEe/ansible_modlib.zip/ansible/module_utils/nxos.py\", line 313, in load_config\nNameError: global name 'commands' is not defined\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

```



Discussion:
```
pylint -E lib/ansible/module_utils/nxos.py
No config file found, using default configuration
************* Module ansible.module_utils.nxos
E:278, 0: Sequence index is not an int, slice, or instance with __index__ (invalid-sequence-index)
E:313,20: Undefined variable 'commands' (undefined-variable)
E:314,26: Undefined variable 'commands' (undefined-variable)
```

Resolving patch:
diff --git a/lib/ansible/module_utils/nxos.py b/lib/ansible/module_utils/nxos.py
--- a/lib/ansible/module_utils/nxos.py
+++ b/lib/ansible/module_utils/nxos.py
@@ -306,7 +306,7 @@ def run_commands(self, commands, check_rc=True):
 
         return responses
 
-    def load_config(self, config):
+    def load_config(self, commands):
         """Sends the ordered set of commands to the device
         """
         cmds = ['configure terminal']


Test patch: