Check right CLI context is set on iosxr action plugin (#22108)

Fixes #21994
This commit is contained in:
Ricardo Carrillo Cruz 2017-03-01 11:44:12 +01:00 committed by John R Barker
parent f09df1820b
commit 029ccf9aa0

View file

@ -64,19 +64,23 @@ class ActionModule(_ActionModule):
socket_path = self._get_socket_path(pc)
if not os.path.exists(socket_path):
# start the connection if it isn't started
display.vvvv('calling open_shell()', pc.remote_addr)
rc, out, err = connection.exec_command('open_shell()')
if rc != 0:
return {'failed': True, 'msg': 'unable to open shell', 'rc': rc}
else:
# make sure we are in the right cli context which should be
# enable mode and not config module
rc, out, err = connection.exec_command('prompt()')
while str(out).strip().endswith(')#'):
display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr)
connection.exec_command('exit')
rc, out, err = connection.exec_command('prompt()')
task_vars['ansible_socket'] = socket_path
result = super(ActionModule, self).run(tmp, task_vars)
# need to make sure to leave config mode if the module didn't clean up
rc, out, err = connection.exec_command('prompt()')
if str(out).strip().endswith(')#'):
connection.exec_command('exit')
return result
def _get_socket_path(self, play_context):