update eos_command doc strings and return values

This change updates the returns values from eos_command to be consistent
with network modules. It now returns stdout, stdout_lines and failed_conditionals
pull/18777/head
Peter Sprygada 9 years ago committed by Matt Clay
parent 79b50f5cf8
commit 279ca048ae

@ -23,7 +23,7 @@ version_added: "2.1"
author: "Peter sprygada (@privateip)" author: "Peter sprygada (@privateip)"
short_description: Run arbitrary command on EOS device short_description: Run arbitrary command on EOS device
description: description:
- Sends an aribtrary command to and EOS node and returns the results - Sends an aribtrary set of commands to and EOS node and returns the results
read from the device. The M(eos_command) modulule includes an read from the device. The M(eos_command) modulule includes an
argument that will cause the module to wait for a specific condition argument that will cause the module to wait for a specific condition
before returning or timing out if the condition is not met. before returning or timing out if the condition is not met.
@ -66,11 +66,13 @@ options:
""" """
EXAMPLES = """ EXAMPLES = """
- eos_command:
commands: "{{ lookup('file', 'commands.txt') }}"
- eos_command: - eos_command:
commands: commands:
- show version - show interface {{ item }}
register: output with_items: interfaces
- eos_command: - eos_command:
commands: commands:
@ -87,23 +89,26 @@ EXAMPLES = """
- "result[2] contains '4.15.0F'" - "result[2] contains '4.15.0F'"
- "result[1].interfaces.Management1.interfaceAddress[0].primaryIp.maskLen eq 24" - "result[1].interfaces.Management1.interfaceAddress[0].primaryIp.maskLen eq 24"
- "result[0].modelName == 'vEOS'" - "result[0].modelName == 'vEOS'"
""" """
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
@ -113,12 +118,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):
@ -216,11 +220,11 @@ def main():
except AttributeError, exc: except AttributeError, exc:
module.fail_json(msg=exc.message) module.fail_json(msg=exc.message)
result = dict(changed=False, result=list()) result = dict(changed=False)
while retries > 0: while retries > 0:
response = module.execute(commands) response = module.execute(commands)
result['result'] = response result['stdout'] = response
for index, cmd in enumerate(commands): for index, cmd in enumerate(commands):
if cmd.endswith('json'): if cmd.endswith('json'):
@ -239,6 +243,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