From 1acd25893100728afc7c3bbadbe1dc3984a52031 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Wed, 12 Oct 2016 20:16:20 -0400 Subject: [PATCH] fixes issue in eos shared module for earlier versions of EOS (#17980) Earlier versions of EOS that do not support config sessions would create an exception. This fix will now check if the device supports sessions and if it doesn't, it will fall back to not using sessions (cherry picked from commit 3badb212fb319f43eb789a19db0a9e3a45cdf114) --- lib/ansible/module_utils/eos.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/eos.py b/lib/ansible/module_utils/eos.py index 2569a321e38..e1d926f1335 100644 --- a/lib/ansible/module_utils/eos.py +++ b/lib/ansible/module_utils/eos.py @@ -50,7 +50,7 @@ class EosConfigMixin(object): cmds = ['configure terminal'] cmds.extend(to_list(commands)) cmds.append('end') - responses = self.execute(commands) + responses = self.execute(cmds) return responses[1:-1] def get_config(self, include_defaults=False, **kwargs): @@ -60,6 +60,12 @@ class EosConfigMixin(object): return self.execute([cmd])[0] def load_config(self, config, commit=False, replace=False): + if self.supports_sessions(): + return self.load_config_session(config, commit, replace) + else: + return self.configure(config) + + def load_config_session(self, config, commit=False, replace=False): """ Loads the configuration into the remote device """ session = 'ansible_%s' % int(time.time()) @@ -116,6 +122,17 @@ class EosConfigMixin(object): commands = ['configure session %s' % session, 'abort'] self.execute(commands) + def supports_sessions(self): + try: + if isinstance(self, Eapi): + self.execute('show configuration sessions', output='text') + else: + self.execute('show configuration sessions') + return True + except NetworkError: + return False + + class Eapi(EosConfigMixin):