fixes return passing output from command through jxmlease in junos_command (#5044)
The return string from the commands was not being passed through the jxmlease library and therefore being returned as a string instead of a json data structure. This also adds back the missing xml key in the return that includes the raw xml string. fixes #5001pull/4420/head
parent
c3f815a6f6
commit
a5b32fa0d1
|
@ -151,15 +151,23 @@ failed_conditionals:
|
||||||
retured: failed
|
retured: failed
|
||||||
type: list
|
type: list
|
||||||
sample: ['...', '...']
|
sample: ['...', '...']
|
||||||
|
|
||||||
|
xml:
|
||||||
|
description: The raw XML reply from the device
|
||||||
|
returned: when format is xml
|
||||||
|
type: list
|
||||||
|
sample: [['...', '...'], ['...', '...']]
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import ansible.module_utils.junos
|
import ansible.module_utils.junos
|
||||||
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import get_exception
|
from ansible.module_utils.basic import get_exception
|
||||||
from ansible.module_utils.network import NetworkModule, NetworkError
|
from ansible.module_utils.network import NetworkModule, NetworkError
|
||||||
from ansible.module_utils.netcli import CommandRunner
|
from ansible.module_utils.netcli import CommandRunner
|
||||||
from ansible.module_utils.netcli import AddCommandError, FailedConditionsError
|
from ansible.module_utils.netcli import AddCommandError, FailedConditionsError
|
||||||
|
from ansible.module_utils.junos import xml_to_json
|
||||||
|
|
||||||
VALID_KEYS = {
|
VALID_KEYS = {
|
||||||
'cli': frozenset(['command', 'output', 'prompt', 'response']),
|
'cli': frozenset(['command', 'output', 'prompt', 'response']),
|
||||||
|
@ -270,15 +278,19 @@ def main():
|
||||||
module.fail_json(msg=str(exc))
|
module.fail_json(msg=str(exc))
|
||||||
|
|
||||||
result = dict(changed=False, stdout=list())
|
result = dict(changed=False, stdout=list())
|
||||||
|
xmlout = list()
|
||||||
|
|
||||||
for cmd in commands:
|
for cmd in commands:
|
||||||
try:
|
try:
|
||||||
output = runner.get_command(cmd['command'], cmd.get('output'))
|
output = runner.get_command(cmd['command'], cmd.get('output'))
|
||||||
|
xmlout.append(output)
|
||||||
|
output = xml_to_json(output)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
output = 'command not executed due to check_mode, see warnings'
|
output = 'command not executed due to check_mode, see warnings'
|
||||||
result['stdout'].append(output)
|
result['stdout'].append(output)
|
||||||
|
|
||||||
result['warnings'] = warnings
|
result['warnings'] = warnings
|
||||||
|
result['xml'] = xmlout
|
||||||
result['stdout_lines'] = list(to_lines(result['stdout']))
|
result['stdout_lines'] = list(to_lines(result['stdout']))
|
||||||
|
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
Loading…
Reference in New Issue