From 765a76885b031d45f216a379fee94fa0b5f2776d Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Tue, 20 Sep 2016 16:30:09 -0400 Subject: [PATCH] fixes issue where config sessions where left behind (#17673) When using the Cli transport, if the session hung on a command and the socket timed out, the config session would be left behind. This change will allow the shell to try to get control back and remove the config session, assuming the channel is still open. fixes ansible/ansible-modules-core#4945 --- lib/ansible/module_utils/eos.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/eos.py b/lib/ansible/module_utils/eos.py index 81d06720a4..e17ea18e34 100644 --- a/lib/ansible/module_utils/eos.py +++ b/lib/ansible/module_utils/eos.py @@ -29,7 +29,7 @@ import re import time -from ansible.module_utils.basic import json +from ansible.module_utils.basic import json, get_exception from ansible.module_utils.network import ModuleStub, NetworkError, NetworkModule from ansible.module_utils.network import add_argument, register_transport, to_list from ansible.module_utils.netcli import Command @@ -81,6 +81,11 @@ class EosConfigMixin(object): else: self.execute(['no configure session %s' % session]) except NetworkError: + exc = get_exception() + if 'timeout trying to send command' in exc.message: + # try to get control back and get out of config mode + if isinstance(self, Cli): + self.execute(['\x03', 'end']) self.abort_config(session) diff = None raise