From c566cb32779d15a004fc5e741f5d95dec56c8193 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Tue, 9 Feb 2016 14:35:30 -0500 Subject: [PATCH] update nxos_command doc strings and return values This modifies the return values to make them consistent across all network command modules. The module now returns stdout, stdout_lines and failed_conditionals --- network/nxos/nxos_command.py | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/network/nxos/nxos_command.py b/network/nxos/nxos_command.py index fc113a91c24..feed205192d 100644 --- a/network/nxos/nxos_command.py +++ b/network/nxos/nxos_command.py @@ -66,11 +66,17 @@ options: """ EXAMPLES = """ +- nxos_command: + commands: ["show version"] + +- nxos_command: + commands: "{{ lookup('file', 'commands.txt') }}" - nxos_command: commands: - - show version - register: output + - "show interface {{ item }}" + with_items: interfaces + - nxos_command: commands: @@ -90,19 +96,23 @@ EXAMPLES = """ """ RETURN = """ - -result: +stdout: description: the set of responses from the commands returned: always type: list sample: ['...', '...'] -failed_conditionals: +stdout_lines: + description: The value of stdout split into a list + returned: always + type: list + sample: [['...', '...'], ['...'], ['...']] + +failed_conditions: description: the conditionals that failed retured: failed type: list sample: ['...', '...'] - """ import time @@ -112,12 +122,11 @@ import json INDEX_RE = re.compile(r'(\[\d+\])') -def get_response(data): - try: - json_data = json.loads(data) - except ValueError: - json_data = None - return dict(data=data, json=json_data) +def to_lines(stdout): + for item in stdout: + if isinstance(item, basestring): + item = str(item).split('\n') + yield item class Conditional(object): @@ -225,7 +234,7 @@ def main(): while retries > 0: try: response = module.execute(commands, **kwargs) - result['result'] = response + result['stdout'] = response except ShellError: module.fail_json(msg='failed to run commands') @@ -246,6 +255,7 @@ def main(): failed_conditions = [item.raw for item in queue] module.fail_json(msg='timeout waiting for value', failed_conditions=failed_conditions) + result['stdout_lines'] = list(to_lines(result['stdout'])) return module.exit_json(**result)