summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbdowling <bdowling@users.noreply.github.com>2016-11-07 19:48:43 -0600
committerPeter Sprygada <privateip@users.noreply.github.com>2016-11-07 20:48:43 -0500
commit933f508cfa050c79d8e36b2624ddb2d0eea26739 (patch)
treea8b1998f9301b7d2cae470a13d5c4749fead1ba5
parentb8efa3cde0b4e8f1d3ab24fa86cf29a7cf7f1100 (diff)
downloadansible-modules-core-933f508cfa050c79d8e36b2624ddb2d0eea26739.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
-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 26a318de..f7a2d5e6 100644
--- a/network/ios/ios_config.py
+++ b/network/ios/ios_config.py
@@ -367,7 +367,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)