mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
roll up of updates to vyos_config module
* remove 'udpates' argument * add required_if dependencies * clean up functions * update doc strings
This commit is contained in:
parent
8444b1ed8f
commit
a9557bc12b
1 changed files with 9 additions and 30 deletions
|
@ -56,17 +56,6 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: line
|
default: line
|
||||||
choices: ['line', 'none']
|
choices: ['line', 'none']
|
||||||
update:
|
|
||||||
description:
|
|
||||||
- The C(update) argument controls the method used to update the
|
|
||||||
remote device configuration. This argument accepts two valid
|
|
||||||
options, C(merge) or C(check). When C(merge) is specified, the
|
|
||||||
configuration is merged into the current active config. When
|
|
||||||
C(check) is specified, the module returns the set of updates
|
|
||||||
that would be applied to the active configuration.
|
|
||||||
required: false
|
|
||||||
default: merge
|
|
||||||
choices: ['merge', 'check']
|
|
||||||
backup:
|
backup:
|
||||||
description:
|
description:
|
||||||
- The C(backup) argument will backup the current devices active
|
- The C(backup) argument will backup the current devices active
|
||||||
|
@ -108,7 +97,7 @@ updates:
|
||||||
returned: always
|
returned: always
|
||||||
type: list
|
type: list
|
||||||
sample: ['...', '...']
|
sample: ['...', '...']
|
||||||
removed:
|
filtered:
|
||||||
description: The list of configuration commands removed to avoid a load failure
|
description: The list of configuration commands removed to avoid a load failure
|
||||||
returned: always
|
returned: always
|
||||||
type: list
|
type: list
|
||||||
|
@ -153,11 +142,6 @@ CONFIG_FILTERS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def check_args(module, warnings):
|
|
||||||
if module.params['save'] and module.params['update'] == 'check':
|
|
||||||
warnings.append('The configuration will not be saved when update '
|
|
||||||
'is set to check')
|
|
||||||
|
|
||||||
def config_to_commands(config):
|
def config_to_commands(config):
|
||||||
set_format = config.startswith('set') or config.startswith('delete')
|
set_format = config.startswith('set') or config.startswith('delete')
|
||||||
candidate = NetworkConfig(indent=4, contents=config, device_os='junos')
|
candidate = NetworkConfig(indent=4, contents=config, device_os='junos')
|
||||||
|
@ -181,7 +165,6 @@ def get_config(module, result):
|
||||||
contents = module.params['config']
|
contents = module.params['config']
|
||||||
if not contents:
|
if not contents:
|
||||||
contents = module.config.get_config(output='set').split('\n')
|
contents = module.config.get_config(output='set').split('\n')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
contents = config_to_commands(contents)
|
contents = config_to_commands(contents)
|
||||||
|
|
||||||
|
@ -223,11 +206,11 @@ def diff_config(commands, config):
|
||||||
return list(updates)
|
return list(updates)
|
||||||
|
|
||||||
def sanitize_config(config, result):
|
def sanitize_config(config, result):
|
||||||
result['removed'] = list()
|
result['filtered'] = list()
|
||||||
for regex in CONFIG_FILTERS:
|
for regex in CONFIG_FILTERS:
|
||||||
for index, line in enumerate(list(config)):
|
for index, line in enumerate(list(config)):
|
||||||
if regex.search(line):
|
if regex.search(line):
|
||||||
result['removed'].append(line)
|
result['filtered'].append(line)
|
||||||
del config[index]
|
del config[index]
|
||||||
|
|
||||||
def load_config(module, commands, result):
|
def load_config(module, commands, result):
|
||||||
|
@ -264,25 +247,24 @@ def run(module, result):
|
||||||
if module.params['update'] != 'check':
|
if module.params['update'] != 'check':
|
||||||
load_config(module, updates, result)
|
load_config(module, updates, result)
|
||||||
|
|
||||||
if result.get('removed'):
|
if result.get('filtered'):
|
||||||
result['warnings'].append('Some configuration commands where '
|
result['warnings'].append('Some configuration commands where '
|
||||||
'removed, please see the removed key')
|
'removed, please see the filtered key')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
lines=dict(type='list'),
|
|
||||||
src=dict(type='path'),
|
src=dict(type='path'),
|
||||||
|
lines=dict(type='list'),
|
||||||
|
|
||||||
match=dict(default='line', choices=['line', 'none']),
|
match=dict(default='line', choices=['line', 'none']),
|
||||||
|
|
||||||
update=dict(default='merge', choices=['merge', 'check']),
|
|
||||||
backup=dict(default=False, type='bool'),
|
|
||||||
comment=dict(default=DEFAULT_COMMENT),
|
comment=dict(default=DEFAULT_COMMENT),
|
||||||
|
|
||||||
config=dict(),
|
config=dict(),
|
||||||
|
|
||||||
|
backup=dict(default=False, type='bool'),
|
||||||
save=dict(default=False, type='bool'),
|
save=dict(default=False, type='bool'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -293,10 +275,7 @@ def main():
|
||||||
mutually_exclusive=mutually_exclusive,
|
mutually_exclusive=mutually_exclusive,
|
||||||
supports_check_mode=True)
|
supports_check_mode=True)
|
||||||
|
|
||||||
warnings = list()
|
result = dict(changed=False)
|
||||||
check_args(module, warnings)
|
|
||||||
|
|
||||||
result = dict(changed=False, warnings=warnings)
|
|
||||||
|
|
||||||
if module.params['backup']:
|
if module.params['backup']:
|
||||||
result['__backup__'] = module.config.get_config()
|
result['__backup__'] = module.config.get_config()
|
||||||
|
|
Loading…
Reference in a new issue