From 05ca246ddc8f3b369efe5e4813951c47275af5cd Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Fri, 15 Jul 2016 16:12:12 -0400 Subject: [PATCH] adds new function to check config for unsupported commands Some commands fail when being set so the load_config function will now filter those commands out and return them in the result key as filtered. --- lib/ansible/module_utils/vyos.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/ansible/module_utils/vyos.py b/lib/ansible/module_utils/vyos.py index 86c593a7a1..7002e46d74 100644 --- a/lib/ansible/module_utils/vyos.py +++ b/lib/ansible/module_utils/vyos.py @@ -28,6 +28,10 @@ from ansible.module_utils.shell import Shell, ShellError, HAS_PARAMIKO DEFAULT_COMMENT = 'configured by vyos_config' +FILTERS = [ + re.compile(r'set system login user \S+ authentication encrypted-password') +] + def argument_spec(): return dict( running_config=dict(aliases=['config']), @@ -68,6 +72,14 @@ def diff_config(candidate, config): return list(updates) +def check_config(config, result): + result['filtered'] = list() + for regex in FILTERS: + for index, line in enumerate(list(config)): + if regex.search(line): + result['filtered'].append(line) + del config[index] + def load_candidate(module, candidate): config = get_config(module) @@ -79,6 +91,7 @@ def load_candidate(module, candidate): result = dict(changed=False) if updates: + check_config(updates, result) diff = module.config.load_config(updates) if diff: result['diff'] = dict(prepared=diff)