mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
check ios cli context and exits config mode if there (#21544)
This commit is contained in:
parent
eeaec56ed5
commit
a01288859d
1 changed files with 9 additions and 3 deletions
|
@ -31,13 +31,19 @@ from ansible.module_utils.ios import ios_argument_spec
|
||||||
from ansible.module_utils.basic import AnsibleFallbackNotFound
|
from ansible.module_utils.basic import AnsibleFallbackNotFound
|
||||||
from ansible.module_utils._text import to_bytes
|
from ansible.module_utils._text import to_bytes
|
||||||
|
|
||||||
|
try:
|
||||||
|
from __main__ import display
|
||||||
|
except ImportError:
|
||||||
|
from ansible.utils.display import Display
|
||||||
|
display = Display()
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
class ActionModule(_ActionModule):
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
def run(self, tmp=None, task_vars=None):
|
||||||
|
|
||||||
if self._play_context.connection != 'local':
|
if self._play_context.connection != 'local':
|
||||||
return dict(
|
return dict(
|
||||||
fail=True,
|
failed=True,
|
||||||
msg='invalid connection specified, expected connection=local, '
|
msg='invalid connection specified, expected connection=local, '
|
||||||
'got %s' % self._play_context.connection
|
'got %s' % self._play_context.connection
|
||||||
)
|
)
|
||||||
|
@ -70,9 +76,9 @@ class ActionModule(_ActionModule):
|
||||||
results = super(ActionModule, self).run(tmp, task_vars)
|
results = super(ActionModule, self).run(tmp, task_vars)
|
||||||
|
|
||||||
# need to make sure to leave config mode if the module didn't clean up
|
# need to make sure to leave config mode if the module didn't clean up
|
||||||
rc, out, err = connection.exec_command('EXEC: prompt()')
|
rc, out, err = connection.exec_command('prompt()')
|
||||||
if str(out).strip().endswith(')#'):
|
if str(out).strip().endswith(')#'):
|
||||||
connection.exec_command('EXEC: exit')
|
connection.exec_command('exit')
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue