Repository: ansible/ansible

Issue:
nxos_feature fails enabling or disabling
##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
nxos_feature

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible --version
ansible 2.2.1.0 (stable-2.2 0c153146e3) last updated 2017/01/15 14:21:01 (GMT +200)
  lib/ansible/modules/core: (detached HEAD b387c9c1e2) last updated 2017/01/15 14:21:34 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD e9bf9fd844) last updated 2017/01/15 14:21:52 (GMT +200)
  config file = 
  configured module search path = Default w/o overrides
```

##### 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.
-->
running on OSX

##### SUMMARY
<!--- Explain the problem briefly -->
Trying to enable feature but module fails.

##### 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
con_details:
  username: "{{ nxos_username }}"
  password: "{{ nxos_password }}"
  host: "{{ inventory_hostname }}"
  transport: cli

- name: Enable Tacacs
  nxos_feature:
    feature: tacacs
    state: enabled
    provider: "{{ con_details }}"
```

<!--- 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

```
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/var/folders/pz/zc91xtc54w99yt0h33t6gq9m0000gp/T/ansible_rtyOeQ/ansible_module_nxos_feature.py", line 481, in <module>
    main()
  File "/var/folders/pz/zc91xtc54w99yt0h33t6gq9m0000gp/T/ansible_rtyOeQ/ansible_module_nxos_feature.py", line 443, in main
    available_features = get_available_features(feature, module)
  File "/var/folders/pz/zc91xtc54w99yt0h33t6gq9m0000gp/T/ansible_rtyOeQ/ansible_module_nxos_feature.py", line 340, in get_available_features
    split_body = body[0].splitlines()
AttributeError: 'dict' object has no attribute 'splitlines'

fatal: [10.56.140.14]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_name": "nxos_feature"
    }, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/pz/zc91xtc54w99yt0h33t6gq9m0000gp/T/ansible_rtyOeQ/ansible_module_nxos_feature.py\", line 481, in <module>\n    main()\n  File \"/var/folders/pz/zc91xtc54w99yt0h33t6gq9m0000gp/T/ansible_rtyOeQ/ansible_module_nxos_feature.py\", line 443, in main\n    available_features = get_available_features(feature, module)\n  File \"/var/folders/pz/zc91xtc54w99yt0h33t6gq9m0000gp/T/ansible_rtyOeQ/ansible_module_nxos_feature.py\", line 340, in get_available_features\n    split_body = body[0].splitlines()\nAttributeError: 'dict' object has no attribute 'splitlines'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE"
}
```



Discussion:
cc @jedelman8 @GGabriele @privateip @gundalow @Qalthos
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @rcarrillocruz
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @rahushen @mikewiebe
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @trishnaguha
[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_feature.py b/lib/ansible/modules/network/nxos/nxos_feature.py
--- a/lib/ansible/modules/network/nxos/nxos_feature.py
+++ b/lib/ansible/modules/network/nxos/nxos_feature.py
@@ -95,8 +95,11 @@ def get_available_features(feature, module):
 
     command = {'command': command, 'output': 'text'}
 
-    body = run_commands(module, [command])
-    split_body = body[0].splitlines()
+    try:
+        body = run_commands(module, [command])[0]
+        split_body = body.splitlines()
+    except (KeyError, AttributeError, IndexError):
+        return {}
 
     for line in split_body:
         try:


Test patch: