diff --git a/lib/ansible/module_utils/ios.py b/lib/ansible/module_utils/ios.py index 38412f6eaf..480c8f9880 100644 --- a/lib/ansible/module_utils/ios.py +++ b/lib/ansible/module_utils/ios.py @@ -50,6 +50,16 @@ def check_args(module, warnings): warnings.append('argument %s has been deprecated and will be ' 'removed in a future version' % key) +def get_defaults_flag(module): + rc, out, err = exec_command(module, 'show running-config ?') + + commands = set() + for line in out.splitlines(): + if line: + commands.add(line.strip().split()[0]) + + return 'all' if 'all' in commands else 'full' + def get_config(module, flags=[]): cmd = 'show running-config ' cmd += ' '.join(flags) diff --git a/lib/ansible/modules/network/ios/ios_config.py b/lib/ansible/modules/network/ios/ios_config.py index 95d8edcb45..7876068785 100644 --- a/lib/ansible/modules/network/ios/ios_config.py +++ b/lib/ansible/modules/network/ios/ios_config.py @@ -206,6 +206,7 @@ import re import time from ansible.module_utils.ios import run_commands, get_config, load_config +from ansible.module_utils.ios import get_defaults_flag from ansible.module_utils.ios import ios_argument_spec from ansible.module_utils.ios import check_args as ios_check_args from ansible.module_utils.basic import AnsibleModule @@ -266,7 +267,7 @@ def get_running_config(module): if not contents: flags = [] if module.params['defaults']: - flags.append('all') + flags.append(get_defaults_flag(module)) contents = get_config(module, flags=flags) contents, banners = extract_banners(contents) return NetworkConfig(indent=1, contents=contents), banners