diff --git a/network/nxos/nxos_command.py b/network/nxos/nxos_command.py index 21da8d70a3f..186b521be01 100644 --- a/network/nxos/nxos_command.py +++ b/network/nxos/nxos_command.py @@ -20,7 +20,7 @@ DOCUMENTATION = """ --- module: nxos_command version_added: "2.1" -author: "Peter sprygada (@privateip)" +author: "Peter Sprygada (@privateip)" short_description: Run arbitrary command on Cisco NXOS devices description: - Sends an aribtrary command to an NXOS node and returns the results @@ -62,7 +62,6 @@ options: trying the command again. required: false default: 1 - """ EXAMPLES = """ @@ -118,7 +117,6 @@ failed_conditions: import time import shlex import re -import json INDEX_RE = re.compile(r'(\[\d+\])') @@ -127,12 +125,6 @@ def to_lines(stdout): if isinstance(item, basestring): item = str(item).split('\n') yield item -def get_response(data): - try: - json_data = json.loads(data) - except ValueError: - json_data = None - return dict(data=data, json=json_data) def main(): spec = dict( @@ -173,7 +165,12 @@ def main(): for index, cmd in enumerate(commands): if cmd.endswith('json'): - response[index] = json.loads(response[index]) + try: + response[index] = module.from_json(response[index]) + except ValueError, exc: + module.fail_json(msg='failed to parse json response', + exc_type=str(type(exc)), exc_message=str(exc), + response=response[index]) for item in list(queue): if item(response):