Add support for multiple answers in cli_command module (#44560)

* Add support for multiple answers in cli_command module

*  Add multiple answers support for multiple prompts

Depends on PR #44492

* Doc update
This commit is contained in:
Ganesh Nalawade 2018-08-23 19:19:18 +05:30 committed by Nathaniel Case
parent 6c05e03fea
commit 64045cb024

View file

@ -30,10 +30,14 @@ options:
- A single regex pattern or a sequence of patterns to evaluate the expected - A single regex pattern or a sequence of patterns to evaluate the expected
prompt from I(command). prompt from I(command).
required: false required: false
type: list
answer: answer:
description: description:
- The answer to reply with if I(prompt) is matched. - The answer to reply with if I(prompt) is matched. The value can be a single answer
or a list of answer for multiple prompts. In case the command execution results in
multiple prompts the sequence of the prompt and excepted answer should be in same order.
required: false required: false
type: list
sendonly: sendonly:
description: description:
- The boolean value, that when set to true will send I(command) to the - The boolean value, that when set to true will send I(command) to the
@ -63,11 +67,23 @@ EXAMPLES = """
command: "{{ item }}" command: "{{ item }}"
prompt: prompt:
- "Exit with uncommitted changes" - "Exit with uncommitted changes"
answer: yes answer: 'y'
loop: loop:
- configure - configure
- set system syslog file test any any - set system syslog file test any any
- exit - exit
- name: multiple prompt, multiple answer
cli_command:
command: "copy sftp sftp://user@host//user/test.img"
prompt:
- "Confirm download operation"
- "Password"
- "Do you want to change that to the standby image"
answer:
- 'y'
- <password>
- 'y'
""" """
RETURN = """ RETURN = """
@ -102,7 +118,7 @@ def main():
argument_spec = dict( argument_spec = dict(
command=dict(type='str', required=True), command=dict(type='str', required=True),
prompt=dict(type='list', required=False), prompt=dict(type='list', required=False),
answer=dict(type='str', required=False), answer=dict(type='list', required=False),
sendonly=dict(type='bool', default=False, required=False), sendonly=dict(type='bool', default=False, required=False),
) )
required_together = [['prompt', 'answer']] required_together = [['prompt', 'answer']]