mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
check cli context to be sure out of config mode in ios (#21493)
This change will now check the cli context after a module runs and if the cli is still in config mode it will exit config mode. Also fixes a minor issue with converting list of commands to a dict fixes #21481
This commit is contained in:
parent
edf2b00614
commit
34e6cc788f
2 changed files with 18 additions and 9 deletions
|
@ -65,18 +65,19 @@ def get_config(module, flags=[]):
|
||||||
_DEVICE_CONFIGS[cmd] = cfg
|
_DEVICE_CONFIGS[cmd] = cfg
|
||||||
return cfg
|
return cfg
|
||||||
|
|
||||||
def to_commands(commands):
|
def to_commands(module, commands):
|
||||||
transform = ComplexList(dict(
|
spec = {
|
||||||
command=dict(key=True),
|
'command': dict(key=True),
|
||||||
prompt=dict(),
|
'prompt': dict(),
|
||||||
response=dict()
|
'response': dict()
|
||||||
))
|
}
|
||||||
|
transform = ComplexList(spec, module)
|
||||||
return transform(commands)
|
return transform(commands)
|
||||||
|
|
||||||
|
|
||||||
def run_commands(module, commands, check_rc=True):
|
def run_commands(module, commands, check_rc=True):
|
||||||
responses = list()
|
responses = list()
|
||||||
commands = to_commands(to_list(commands))
|
commands = to_commands(module, to_list(commands))
|
||||||
for cmd in commands:
|
for cmd in commands:
|
||||||
cmd = module.jsonify(cmd)
|
cmd = module.jsonify(cmd)
|
||||||
rc, out, err = exec_command(module, cmd)
|
rc, out, err = exec_command(module, cmd)
|
||||||
|
|
|
@ -53,10 +53,11 @@ class ActionModule(_ActionModule):
|
||||||
pc.become = provider['authorize'] or False
|
pc.become = provider['authorize'] or False
|
||||||
pc.become_pass = provider['auth_pass']
|
pc.become_pass = provider['auth_pass']
|
||||||
|
|
||||||
|
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
|
||||||
|
|
||||||
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
|
||||||
connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
|
|
||||||
connection.exec_command('EXEC: show version')
|
connection.exec_command('EXEC: show version')
|
||||||
|
|
||||||
task_vars['ansible_socket'] = socket_path
|
task_vars['ansible_socket'] = socket_path
|
||||||
|
@ -66,7 +67,14 @@ class ActionModule(_ActionModule):
|
||||||
self._play_context.become_method = None
|
self._play_context.become_method = None
|
||||||
|
|
||||||
|
|
||||||
return 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
|
||||||
|
rc, out, err = connection.exec_command('EXEC: prompt()')
|
||||||
|
if str(out).strip().endswith(')#'):
|
||||||
|
connection.exec_command('EXEC: exit')
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
def _get_socket_path(self, play_context):
|
def _get_socket_path(self, play_context):
|
||||||
ssh = connection_loader.get('ssh', class_only=True)
|
ssh = connection_loader.get('ssh', class_only=True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue