From 6caed0c38b8c634856add865fb3c6007a27e718a Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Tue, 18 Dec 2018 10:34:32 -0500 Subject: [PATCH] ios retry config if section filter fails (#49485) * Attempt to work around devices that don't understand | section * Fix case of no flags --- lib/ansible/module_utils/network/ios/ios.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/network/ios/ios.py b/lib/ansible/module_utils/network/ios/ios.py index 0331d58bf15..7aeae8e313a 100644 --- a/lib/ansible/module_utils/network/ios/ios.py +++ b/lib/ansible/module_utils/network/ios/ios.py @@ -104,7 +104,13 @@ def get_defaults_flag(module): def get_config(module, flags=None): - flag_str = ' '.join(to_list(flags)) + flags = to_list(flags) + + section_filter = False + if flags and 'section' in flags[-1]: + section_filter = True + + flag_str = ' '.join(flags) try: return _DEVICE_CONFIGS[flag_str] @@ -113,7 +119,11 @@ def get_config(module, flags=None): try: out = connection.get_config(flags=flags) except ConnectionError as exc: - module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) + if section_filter: + # Some ios devices don't understand `| section foo` + out = get_config(module, flags=flags[:-1]) + else: + module.fail_json(msg=to_text(exc, errors='surrogate_then_replace')) cfg = to_text(out, errors='surrogate_then_replace').strip() _DEVICE_CONFIGS[flag_str] = cfg return cfg