From 8c7a6cb8ac184f391955d8d349f7bc4b81b374c6 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Mon, 10 Jul 2017 22:05:28 +0530 Subject: [PATCH] Add transformed json output in junos_command (#26382) * Add transformed json output in junos_command Fixes #26363 If the display is in `xml` format for command responses add th transformed `json` output in the result. * Fix CI issue --- lib/ansible/modules/network/junos/junos_command.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/network/junos/junos_command.py b/lib/ansible/modules/network/junos/junos_command.py index 53633b5401..5a513eb835 100644 --- a/lib/ansible/modules/network/junos/junos_command.py +++ b/lib/ansible/modules/network/junos/junos_command.py @@ -157,6 +157,11 @@ stdout_lines: returned: always apart from low level errors (such as action plugin) type: list sample: [['...', '...'], ['...'], ['...']] +output: + description: The set of transformed xml to json format from the commands responses + returned: If the I(display) is in C(xml) format. + type: list + sample: ['...', '...'] failed_conditions: description: The list of conditionals that have failed returned: failed @@ -348,7 +353,7 @@ def main(): responses = rpc(module, items) transformed = list() - + output = list() for item, resp in zip(items, responses): if item['xattrs']['format'] == 'xml': if not HAS_JXMLEASE: @@ -356,7 +361,9 @@ def main(): 'It can be installed using `pip install jxmlease`') try: - transformed.append(jxmlease.parse(resp)) + json_resp = jxmlease.parse(resp) + transformed.append(json_resp) + output.append(json_resp) except: raise ValueError(resp) else: @@ -390,6 +397,9 @@ def main(): 'stdout_lines': to_lines(responses) } + if output: + result['output'] = output + module.exit_json(**result) if __name__ == '__main__':