1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Make prompt inspection explicit for IOS (#54324)

* Be explicit with prompt inspection

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Use regex to evaluate prompt for sub-level config sessions

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>

* Add new line at the end of file

Signed-off-by: NilashishC <nilashishchakraborty8@gmail.com>
This commit is contained in:
Nilashish Chakraborty 2019-04-03 10:55:20 +05:30 committed by GitHub
parent 70f315b7a4
commit ee08b009dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)}