From ee08b009dd92ddd9f19e9eca6bc238faa1c12f4e Mon Sep 17 00:00:00 2001 From: Nilashish Chakraborty Date: Wed, 3 Apr 2019 10:55:20 +0530 Subject: [PATCH] Make prompt inspection explicit for IOS (#54324) * Be explicit with prompt inspection Signed-off-by: NilashishC * Use regex to evaluate prompt for sub-level config sessions Signed-off-by: NilashishC * Add new line at the end of file Signed-off-by: NilashishC --- lib/ansible/plugins/action/ios.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ansible/plugins/action/ios.py b/lib/ansible/plugins/action/ios.py index 366fbed059..71c0aa123e 100644 --- a/lib/ansible/plugins/action/ios.py +++ b/lib/ansible/plugins/action/ios.py @@ -19,6 +19,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import re import sys import copy @@ -85,10 +86,9 @@ class ActionModule(ActionNetworkModule): conn = Connection(socket_path) try: out = conn.get_prompt() - while to_text(out, errors='surrogate_then_replace').strip().endswith(')#'): - display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr) - conn.send_command('exit') - out = conn.get_prompt() + if re.search(r'config.*\)#', to_text(out, errors='surrogate_then_replace').strip()): + display.vvvv('wrong context, sending end to device', self._play_context.remote_addr) + conn.send_command('end') except ConnectionError as exc: return {'failed': True, 'msg': to_text(exc)}