junos_template: Simplify arguments. Fixes #3621

Simplify the arguments to junos_template, such that
merge/overwrite/replace can be selected easily.
pull/18777/head
Mike Bryant 8 years ago committed by Matt Clay
parent d738ad0ee0
commit 0027158b74

@ -62,22 +62,13 @@ options:
is set to False, this argument is silently ignored. is set to False, this argument is silently ignored.
required: false required: false
default: configured by junos_template default: configured by junos_template
merge: action:
description: description:
- The C(merge) argument instructs the module to merge the contents - The C(action) argument specifies how the module will apply changes.
of C(src) with the configuration running on the remote device. If
both C(merge) and C(overwrite) are set to false, the configuration
is replaced.
required: false required: false
default: true default: merge
overwrite: choices: ['merge', 'overwrite', 'replace']
description: version_added: "2.2"
- The C(overwrite) argument will overwrite the entire configuration
on the remote device with the contents loaded from C(src). If
both C(merge) and C(overwrite) are set to false, the configuration
is replaced.
required: false
default: false
config_format: config_format:
description: description:
- The C(format) argument specifies the format of the configuration - The C(format) argument specifies the format of the configuration
@ -103,11 +94,11 @@ EXAMPLES = """
- name: replace config hierarchy - name: replace config hierarchy
src: config.j2 src: config.j2
replace: yes action: replace
- name: overwrite the config - name: overwrite the config
src: config.j2 src: config.j2
overwrite: yes action: overwrite
""" """
DEFAULT_COMMENT = 'configured by junos_template' DEFAULT_COMMENT = 'configured by junos_template'
@ -118,40 +109,28 @@ def main():
src=dict(required=True, type='path'), src=dict(required=True, type='path'),
confirm=dict(default=0, type='int'), confirm=dict(default=0, type='int'),
comment=dict(default=DEFAULT_COMMENT), comment=dict(default=DEFAULT_COMMENT),
merge=dict(default=True, type='bool'), action=dict(default='merge', choices=['merge', 'overwrite', 'replace']),
overwrite=dict(default=False, type='bool'),
config_format=dict(choices=['text', 'set', 'xml']), config_format=dict(choices=['text', 'set', 'xml']),
backup=dict(default=False, type='bool'), backup=dict(default=False, type='bool'),
transport=dict(default='netconf', choices=['netconf']) transport=dict(default='netconf', choices=['netconf'])
) )
mutually_exclusive = [('merge', 'overwrite')]
module = get_module(argument_spec=argument_spec, module = get_module(argument_spec=argument_spec,
mutually_exclusive=mutually_exclusive,
supports_check_mode=True) supports_check_mode=True)
comment = module.params['comment'] comment = module.params['comment']
confirm = module.params['confirm'] confirm = module.params['confirm']
commit = not module.check_mode commit = not module.check_mode
merge = module.params['merge'] action = module.params['action']
overwrite = module.params['overwrite']
src = module.params['src'] src = module.params['src']
fmt = module.params['config_format'] fmt = module.params['config_format']
if overwrite and fmt == 'set': if action == 'overwrite' and fmt == 'set':
module.fail_json(msg="overwrite cannot be used when format is " module.fail_json(msg="overwrite cannot be used when format is "
"set per junos documentation") "set per junos documentation")
if merge:
action = 'merge'
elif overwrite:
action = 'overwrite'
else:
action = 'replace'
results = dict(changed=False) results = dict(changed=False)
results['_backup'] = str(module.get_config()).strip() results['_backup'] = str(module.get_config()).strip()

Loading…
Cancel
Save