mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Check right CLI context is set on iosxr action plugin (#22108)
Fixes #21994
This commit is contained in:
parent
f09df1820b
commit
029ccf9aa0
1 changed files with 9 additions and 5 deletions
|
@ -64,19 +64,23 @@ class ActionModule(_ActionModule):
|
||||||
socket_path = self._get_socket_path(pc)
|
socket_path = self._get_socket_path(pc)
|
||||||
if not os.path.exists(socket_path):
|
if not os.path.exists(socket_path):
|
||||||
# start the connection if it isn't started
|
# start the connection if it isn't started
|
||||||
|
display.vvvv('calling open_shell()', pc.remote_addr)
|
||||||
rc, out, err = connection.exec_command('open_shell()')
|
rc, out, err = connection.exec_command('open_shell()')
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
return {'failed': True, 'msg': 'unable to open shell', 'rc': rc}
|
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
|
task_vars['ansible_socket'] = socket_path
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
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
|
return result
|
||||||
|
|
||||||
def _get_socket_path(self, play_context):
|
def _get_socket_path(self, play_context):
|
||||||
|
|
Loading…
Reference in a new issue