diff options
author | Ganesh Nalawade <ganesh634@gmail.com> | 2018-08-23 19:16:42 +0530 |
---|---|---|
committer | Nathaniel Case <this.is@nathanielca.se> | 2018-08-23 09:46:42 -0400 |
commit | e25d8e2b99721ea3b97ac1cede8a40403a2a0012 (patch) | |
tree | 64cabd9cddda6199163858bfd3a7b6c201e3f13a /lib/ansible/plugins/connection | |
parent | 24c26aded8fbdb12ccca17dcaea5b6db48cad319 (diff) | |
download | ansible-e25d8e2b99721ea3b97ac1cede8a40403a2a0012.tar.gz |
Add support for multiple prompt answers in network_cli (#44492)
* Currently network_cli support multiple prompts
single answer as response. This PR adds support
for multiple answers.
* In case of multiple prompts and mulitple answers the
index of a particular prompt in the prompts list should
match with the index in the answer list.
Diffstat (limited to 'lib/ansible/plugins/connection')
-rw-r--r-- | lib/ansible/plugins/connection/network_cli.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index d486ccfb0f..7dfdcbb78c 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -404,19 +404,22 @@ class Connection(NetworkConnectionBase): :arg resp: Byte string containing the raw response from the remote :arg prompts: Sequence of byte strings that we consider prompts for input - :arg answer: Byte string to send back to the remote if we find a prompt. + :arg answer: Sequence of Byte string to send back to the remote if we find a prompt. A carriage return is automatically appended to this string. :returns: True if a prompt was found in ``resp``. False otherwise ''' if not isinstance(prompts, list): prompts = [prompts] + if not isinstance(answer, list): + answer = [answer] prompts = [re.compile(r, re.I) for r in prompts] - for regex in prompts: + for index, regex in enumerate(prompts): match = regex.search(resp) if match: # if prompt_retry_check is enabled to check if same prompt is # repeated don't send answer again. if not prompt_retry_check: + answer = answer[index] if len(answer) > index else answer[0] self._ssh_shell.sendall(b'%s' % answer) if newline: self._ssh_shell.sendall(b'\r') |