From 2567e8157fdb146b8e3742bb21308e221d4434d4 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Tue, 21 Feb 2017 08:27:33 -0500 Subject: [PATCH] fixes bug where handle_prompts failed if list of prompts provided (#21711) This will now automatically convert the prompts to a list and iterate over the regexp looking for a prompt match before supplying the answer. --- lib/ansible/plugins/connection/network_cli.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index 6c869811e76..8cd5f3d8890 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -152,7 +152,6 @@ class Connection(_Connection): return return self.receive(obj) except (socket.timeout, AttributeError) as exc: - #display.debug(traceback.format_exc()) display.vvv(traceback.format_exc()) raise AnsibleConnectionFailure("timeout trying to send command: %s" % command.strip()) @@ -164,12 +163,15 @@ class Connection(_Connection): def _handle_prompt(self, resp, obj): """Matches the command prompt and responds""" - prompt = re.compile(obj['prompt'], re.I) + if not isinstance(obj['prompt'], list): + obj['prompt'] = [obj['prompt']] + prompts = [re.compile(r, re.I) for r in obj['prompt']] answer = obj['answer'] - match = prompt.search(resp) - if match: - self._shell.sendall('%s\r' % answer) - return True + for regex in prompts: + match = regex.search(resp) + if match: + self._shell.sendall('%s\r' % answer) + return True def _sanitize(self, resp, obj=None): """Removes elements from the response before returning to the caller"""