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
This commit is contained in:
parent
6806965bda
commit
ddd13bf53a
2 changed files with 4 additions and 9 deletions
|
@ -148,12 +148,6 @@ from ansible.module_utils.six import string_types
|
||||||
|
|
||||||
VALID_KEYS = ['command', 'prompt', 'response']
|
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):
|
def parse_commands(module):
|
||||||
for cmd in module.params['commands']:
|
for cmd in module.params['commands']:
|
||||||
if isinstance(cmd, string_types):
|
if isinstance(cmd, string_types):
|
||||||
|
@ -216,7 +210,9 @@ def main():
|
||||||
module.fail_json(msg=str(exc), failed_conditions=exc.failed_conditions)
|
module.fail_json(msg=str(exc), failed_conditions=exc.failed_conditions)
|
||||||
except NetworkError:
|
except NetworkError:
|
||||||
exc = get_exception()
|
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())
|
result = dict(changed=False, stdout=list())
|
||||||
|
|
||||||
|
@ -228,7 +224,6 @@ def main():
|
||||||
result['stdout'].append(output)
|
result['stdout'].append(output)
|
||||||
|
|
||||||
result['warnings'] = warnings
|
result['warnings'] = warnings
|
||||||
result['stdout_lines'] = list(to_lines(result['stdout']))
|
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
|
@ -367,7 +367,7 @@ def main():
|
||||||
except NetworkError:
|
except NetworkError:
|
||||||
exc = get_exception()
|
exc = get_exception()
|
||||||
module.disconnect()
|
module.disconnect()
|
||||||
module.fail_json(msg=str(exc))
|
module.fail_json(msg=str(exc), stdout=exc.kwargs.get('stdout'))
|
||||||
|
|
||||||
module.disconnect()
|
module.disconnect()
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
Loading…
Reference in a new issue