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
pull/18777/head
Peter Sprygada 9 years ago committed by Matt Clay
parent 25d724a88d
commit 00d3e33dbf

@ -66,11 +66,17 @@ options:
""" """
EXAMPLES = """ EXAMPLES = """
- nxos_command:
commands: ["show version"]
- nxos_command:
commands: "{{ lookup('file', 'commands.txt') }}"
- nxos_command: - nxos_command:
commands: commands:
- show version - "show interface {{ item }}"
register: output with_items: interfaces
- nxos_command: - nxos_command:
commands: commands:
@ -90,19 +96,23 @@ EXAMPLES = """
""" """
RETURN = """ RETURN = """
stdout:
result:
description: the set of responses from the commands description: the set of responses from the commands
returned: always returned: always
type: list type: list
sample: ['...', '...'] 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 description: the conditionals that failed
retured: failed retured: failed
type: list type: list
sample: ['...', '...'] sample: ['...', '...']
""" """
import time import time
@ -112,12 +122,11 @@ import json
INDEX_RE = re.compile(r'(\[\d+\])') INDEX_RE = re.compile(r'(\[\d+\])')
def get_response(data): def to_lines(stdout):
try: for item in stdout:
json_data = json.loads(data) if isinstance(item, basestring):
except ValueError: item = str(item).split('\n')
json_data = None yield item
return dict(data=data, json=json_data)
class Conditional(object): class Conditional(object):
@ -225,7 +234,7 @@ def main():
while retries > 0: while retries > 0:
try: try:
response = module.execute(commands, **kwargs) response = module.execute(commands, **kwargs)
result['result'] = response result['stdout'] = response
except ShellError: except ShellError:
module.fail_json(msg='failed to run commands') module.fail_json(msg='failed to run commands')
@ -246,6 +255,7 @@ def main():
failed_conditions = [item.raw for item in queue] failed_conditions = [item.raw for item in queue]
module.fail_json(msg='timeout waiting for value', failed_conditions=failed_conditions) 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) return module.exit_json(**result)

Loading…
Cancel
Save