summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbdowling <bdowling@users.noreply.github.com>2016-11-07 19:48:43 -0600
committerPeter Sprygada <psprygada@ansible.com>2016-11-07 20:49:22 -0500
commit43b5b6afd6bc7ec1290f475a92e1c72314019b3f (patch)
tree982589e5c8604a9b943094d4c2d45bf266356af7
parentaf7cb72577d547b9a42369dd12e9399df3cb78a6 (diff)
downloadansible-modules-core-43b5b6afd6bc7ec1290f475a92e1c72314019b3f.tar.gz
ios_mods - added stdout to exception output. Removed to_lines() (#5428)
stdout lines are now available when certain exceptions occur (Ref ansible/ansible#18241) Also noticed that to_lines was essentially handled in lib/ansible/plugins/action/__init__.py -- only difference was it didn't handle a list. to_lines() could be removed across network modules now, but this commit is only for ios_command. Also adds disconnect() to ios_command that was added to ios_config in #5247 (cherry picked from commit 933f508cfa050c79d8e36b2624ddb2d0eea26739)
-rw-r--r--network/ios/ios_command.py11
-rw-r--r--network/ios/ios_config.py2
2 files changed, 4 insertions, 9 deletions
diff --git a/network/ios/ios_command.py b/network/ios/ios_command.py
index 4204a73a..c5923e4e 100644
--- a/network/ios/ios_command.py
+++ b/network/ios/ios_command.py
@@ -148,12 +148,6 @@ from ansible.module_utils.six import string_types
VALID_KEYS = ['command', 'prompt', 'response']
-def to_lines(stdout):
- for item in stdout:
- if isinstance(item, string_types):
- item = str(item).split('\n')
- yield item
-
def parse_commands(module):
for cmd in module.params['commands']:
if isinstance(cmd, string_types):
@@ -216,7 +210,9 @@ def main():
module.fail_json(msg=str(exc), failed_conditions=exc.failed_conditions)
except NetworkError:
exc = get_exception()
- module.fail_json(msg=str(exc))
+ module.disconnect()
+ module.fail_json(msg=str(exc), stdout=exc.kwargs.get('stdout'))
+
result = dict(changed=False, stdout=list())
@@ -228,7 +224,6 @@ def main():
result['stdout'].append(output)
result['warnings'] = warnings
- result['stdout_lines'] = list(to_lines(result['stdout']))
module.exit_json(**result)
diff --git a/network/ios/ios_config.py b/network/ios/ios_config.py
index 1022419a..fb9dd3d3 100644
--- a/network/ios/ios_config.py
+++ b/network/ios/ios_config.py
@@ -323,7 +323,7 @@ def main():
except NetworkError:
exc = get_exception()
module.disconnect()
- module.fail_json(msg=str(exc))
+ module.fail_json(msg=str(exc), stdout=exc.kwargs.get('stdout'))
module.disconnect()
module.exit_json(**result)