From d4b9105c9c4e4dd44f526dc211b10bf38688bd36 Mon Sep 17 00:00:00 2001 From: Paul Neumann Date: Mon, 25 Jun 2018 09:40:32 +0200 Subject: [PATCH] cliconf: Fix use of multiple prompts in send_command (#41885) Upon preparing the commands for sending to the device, cliconf converts the optional prompt to a byte string. However, since there might be multiple prompts specified, the conversion has to happen for each prompt individually. Otherwise, wrong regexes will be compiled in _handle_prompt from network_cli Connection. --- lib/ansible/plugins/cliconf/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ansible/plugins/cliconf/__init__.py b/lib/ansible/plugins/cliconf/__init__.py index 4713d7e9b20..39df307046d 100644 --- a/lib/ansible/plugins/cliconf/__init__.py +++ b/lib/ansible/plugins/cliconf/__init__.py @@ -101,7 +101,7 @@ class CliconfBase(with_metaclass(ABCMeta, object)): logging of any commands based on the `nolog` argument. :param command: The command to send over the connection to the device - :param prompt: A regex pattern to evalue the expected prompt from the command + :param prompt: A single regex pattern or a sequence of patterns to evaluate the expected prompt from the command :param answer: The answer to respond with if the prompt is matched. :param sendonly: Bool value that will send the command but not wait for a result. :param newline: Bool value that will append the newline character to the command @@ -117,7 +117,10 @@ class CliconfBase(with_metaclass(ABCMeta, object)): } if prompt is not None: - kwargs['prompt'] = to_bytes(prompt) + if isinstance(prompt, list): + kwargs['prompt'] = [to_bytes(p) for p in prompt] + else: + kwargs['prompt'] = to_bytes(prompt) if answer is not None: kwargs['answer'] = to_bytes(answer)