From 3b98a2981c5648fbb5a24de437e3f78a298d966e Mon Sep 17 00:00:00 2001 From: bdowling Date: Wed, 24 Jan 2018 09:24:22 -0500 Subject: [PATCH] Fix enable subprompt (#34723) * Look for password prompts at the beginning of the line only * Adds secondary checks for the supplied sub-prompts Handles the case for enable prompts where enable_pass may be incorrect and the deivce is still prompting for the password --- lib/ansible/plugins/connection/network_cli.py | 4 ++++ lib/ansible/plugins/terminal/ios.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py index 30ca54af57..c07e6f7dd1 100644 --- a/lib/ansible/plugins/connection/network_cli.py +++ b/lib/ansible/plugins/connection/network_cli.py @@ -395,6 +395,10 @@ class Connection(ConnectionBase): window = self._strip(recv.read()) if prompts and not handled: handled = self._handle_prompt(window, prompts, answer, newline) + elif prompts and handled: + # check again even when handled, a sub-prompt could be + # repeating (like in the case of a wrong enable password, etc) + self._handle_prompt(window, prompts, answer, newline) if self._find_prompt(window): self._last_response = recv.getvalue() diff --git a/lib/ansible/plugins/terminal/ios.py b/lib/ansible/plugins/terminal/ios.py index 8c6bd7791b..126b6a66e6 100644 --- a/lib/ansible/plugins/terminal/ios.py +++ b/lib/ansible/plugins/terminal/ios.py @@ -63,7 +63,7 @@ class TerminalModule(TerminalBase): if passwd: # Note: python-3.5 cannot combine u"" and r"" together. Thus make # an r string and use to_text to ensure it's text on both py2 and py3. - cmd[u'prompt'] = to_text(r"[\r\n]?password: $", errors='surrogate_or_strict') + cmd[u'prompt'] = to_text(r"[\r\n]password: $", errors='surrogate_or_strict') cmd[u'answer'] = passwd try: