From 4b979742fa1bc52953d8d4f17f94404eb3670ee5 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Tue, 8 May 2018 10:11:54 +0530 Subject: [PATCH] Fetch ios default config is defaults is enabled (#39741) (#39841) If default option is eanbled fetch the current running configuration by adding `all` or `full` flag (cherry picked from commit 09e3b5c92b41ccfbbb83ade05bc11a6ac59271a7) Update Changelog --- changelogs/fragments/ios_defaults_fetch.yaml | 2 ++ lib/ansible/modules/network/ios/ios_config.py | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/ios_defaults_fetch.yaml diff --git a/changelogs/fragments/ios_defaults_fetch.yaml b/changelogs/fragments/ios_defaults_fetch.yaml new file mode 100644 index 0000000000..666895ace0 --- /dev/null +++ b/changelogs/fragments/ios_defaults_fetch.yaml @@ -0,0 +1,2 @@ +bugfixes: +- ios_config - If defaults is enabled append default flag to command (https://github.com/ansible/ansible/pull/39741) diff --git a/lib/ansible/modules/network/ios/ios_config.py b/lib/ansible/modules/network/ios/ios_config.py index 98fb22a686..788f13ff1c 100644 --- a/lib/ansible/modules/network/ios/ios_config.py +++ b/lib/ansible/modules/network/ios/ios_config.py @@ -373,13 +373,13 @@ def load_banners(module, banners): run_commands(module, ['\n']) -def get_running_config(module, current_config=None): +def get_running_config(module, current_config=None, flags=None): contents = module.params['running_config'] + if not contents: if not module.params['defaults'] and current_config: contents, banners = extract_banners(current_config.config_text) else: - flags = get_defaults_flag(module) if module.params['defaults'] else [] contents = get_config(module, flags=flags) contents, banners = extract_banners(contents) return NetworkConfig(indent=1, contents=contents), banners @@ -467,9 +467,10 @@ def main(): result['warnings'] = warnings config = None + flags = get_defaults_flag(module) if module.params['defaults'] else [] if module.params['backup'] or (module._diff and module.params['diff_against'] == 'running'): - contents = get_config(module) + contents = get_config(module, flags=flags) config = NetworkConfig(indent=1, contents=contents) if module.params['backup']: result['__backup__'] = contents @@ -482,7 +483,7 @@ def main(): candidate, want_banners = get_candidate(module) if match != 'none': - config, have_banners = get_running_config(module, config) + config, have_banners = get_running_config(module, config, flags=flags) path = module.params['parents'] configobjs = candidate.difference(config, path=path, match=match, replace=replace) else: