fixes junos_template ignoring the action directive (#5080)

This updates the junos_template to properly process the action
directive when loading the configuration.
pull/18777/head
Peter Sprygada 8 years ago committed by Matt Clay
parent 9436d013d4
commit 9ed01d0cfd

@ -101,9 +101,11 @@ EXAMPLES = """
src: config.j2 src: config.j2
action: overwrite action: overwrite
""" """
from ansible.module_utils.network import NetworkModule
import ansible.module_utils.junos import ansible.module_utils.junos
from ansible.module_utils.basic import get_exception
from ansible.module_utils.network import NetworkModule, NetworkError
DEFAULT_COMMENT = 'configured by junos_template' DEFAULT_COMMENT = 'configured by junos_template'
def main(): def main():
@ -125,24 +127,35 @@ def main():
confirm = module.params['confirm'] confirm = module.params['confirm']
commit = not module.check_mode commit = not module.check_mode
replace = False
overwrite = False
action = module.params['action'] action = module.params['action']
if action == 'overwrite':
overwrite = True
elif action == 'replace':
replace = True
src = module.params['src'] src = module.params['src']
fmt = module.params['config_format'] fmt = module.params['config_format']
if action == '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-pyez documentation")
results = dict(changed=False) results = dict(changed=False)
results['_backup'] = str(module.config.get_config()).strip() results['_backup'] = str(module.config.get_config()).strip()
diff = module.config.load_config(src, action=action, comment=comment, try:
format=fmt, commit=commit, confirm=confirm) diff = module.config.load_config(src, commit=commit, replace=replace,
confirm=confirm, comment=comment, config_format=fmt)
if diff: if diff:
results['changed'] = True results['changed'] = True
results['diff'] = dict(prepared=diff) results['diff'] = dict(prepared=diff)
except NetworkError:
exc = get_exception()
module.fail_json(msg=str(exc), **exc.kwargs)
module.exit_json(**results) module.exit_json(**results)

Loading…
Cancel
Save