Repository: ansible/ansible

Issue:
(P1)nxos_aaa_server_host: MEGA issue list
<!---
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_aaa_server_host

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel e2d6ecfa40) last updated 2017/07/21 14:49:47 (GMT -400)
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/agents-ci/ansible/lib/ansible
  executable location = /root/agents-ci/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### 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.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Ubuntu 14.04

##### SUMMARY
<!--- Explain the problem briefly -->
Several issues
- simple play with only server_type and address set is not idempotent.
- simple play with only server_type and address set can't be removed (i.e state absent).
- play with encrypt type 0 is not idempotent
- nxapi transport is completely and fails with `command can't be piped message`

##### 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 -->
<!--- You can also paste gist.github.com links for larger files -->
https://gist.github.com/rahushen/e5b9e14808436a5387f498ceab19249c

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Plays apply cleanly.

(P1)nxos_aaa_server_host: MEGA issue list
<!---
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_aaa_server_host

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.4.0 (devel e2d6ecfa40) last updated 2017/07/21 14:49:47 (GMT -400)
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/agents-ci/ansible/lib/ansible
  executable location = /root/agents-ci/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### 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.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Ubuntu 14.04

##### SUMMARY
<!--- Explain the problem briefly -->
Several issues
- simple play with only server_type and address set is not idempotent.
- simple play with only server_type and address set can't be removed (i.e state absent).
- play with encrypt type 0 is not idempotent
- nxapi transport is completely and fails with `command can't be piped message`

##### 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 -->
<!--- You can also paste gist.github.com links for larger files -->
https://gist.github.com/rahushen/e5b9e14808436a5387f498ceab19249c

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Plays apply cleanly.



Discussion:
cc @GGabriele @jedelman8 @mikewiebe @privateip @rcarrillocruz @trishnaguha
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
cc @GGabriele @jedelman8 @mikewiebe @privateip @rcarrillocruz @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_aaa_server_host.py b/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py
--- a/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py
+++ b/lib/ansible/modules/network/nxos/nxos_aaa_server_host.py
@@ -167,7 +167,7 @@ def execute_show_command(command, module, command_type='cli_show'):
         cmds = [command]
         body = run_commands(module, cmds)
     elif module.params['transport'] == 'nxapi':
-        cmds = [command]
+        cmds = {'command': command, 'output': 'text'}
         body = run_commands(module, cmds)
 
     return body
@@ -208,7 +208,7 @@ def get_aaa_host_info(module, server_type, address):
 
     body = execute_show_command(command, module, command_type='cli_show_ascii')
 
-    if body:
+    if body[0]:
         try:
             pattern = ('(acct-port \d+)|(timeout \d+)|(auth-port \d+)|'
                        '(key 7 "\w+")|( port \d+)')
@@ -217,9 +217,8 @@ def get_aaa_host_info(module, server_type, address):
                                                     'auth-port': 'auth_port',
                                                     'port': 'tacacs_port',
                                                     'timeout': 'host_timeout'})
-            if aaa_host_info:
-                aaa_host_info['server_type'] = server_type
-                aaa_host_info['address'] = address
+            aaa_host_info['server_type'] = server_type
+            aaa_host_info['address'] = address
         except TypeError:
             return {}
     else:


Test patch: