diff options
author | Peter Sprygada <privateip@users.noreply.github.com> | 2017-02-16 07:54:33 -0500 |
---|---|---|
committer | John R Barker <john@johnrbarker.com> | 2017-02-16 12:54:33 +0000 |
commit | 34e6cc788f12ea39992de9f1f796700d4138798e (patch) | |
tree | 9b34b96961d77602cb903a35305cd0b7ff0b04d6 | |
parent | edf2b006147ae722b036c437a119477d6b93db7c (diff) | |
download | ansible-34e6cc788f12ea39992de9f1f796700d4138798e.tar.gz |
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
-rw-r--r-- | lib/ansible/module_utils/ios.py | 15 | ||||
-rw-r--r-- | lib/ansible/plugins/action/ios.py | 12 |
2 files changed, 18 insertions, 9 deletions
diff --git a/lib/ansible/module_utils/ios.py b/lib/ansible/module_utils/ios.py index b1c146583e..45754701aa 100644 --- a/lib/ansible/module_utils/ios.py +++ b/lib/ansible/module_utils/ios.py @@ -65,18 +65,19 @@ def get_config(module, flags=[]): _DEVICE_CONFIGS[cmd] = cfg return cfg -def to_commands(commands): - transform = ComplexList(dict( - command=dict(key=True), - prompt=dict(), - response=dict() - )) +def to_commands(module, commands): + spec = { + 'command': dict(key=True), + 'prompt': dict(), + 'response': dict() + } + transform = ComplexList(spec, module) return transform(commands) def run_commands(module, commands, check_rc=True): responses = list() - commands = to_commands(to_list(commands)) + commands = to_commands(module, to_list(commands)) for cmd in commands: cmd = module.jsonify(cmd) rc, out, err = exec_command(module, cmd) diff --git a/lib/ansible/plugins/action/ios.py b/lib/ansible/plugins/action/ios.py index bae042c1e3..13daf0fada 100644 --- a/lib/ansible/plugins/action/ios.py +++ b/lib/ansible/plugins/action/ios.py @@ -53,10 +53,11 @@ class ActionModule(_ActionModule): pc.become = provider['authorize'] or False 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) if not os.path.exists(socket_path): # 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') task_vars['ansible_socket'] = socket_path @@ -66,7 +67,14 @@ class ActionModule(_ActionModule): 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): ssh = connection_loader.get('ssh', class_only=True) |