fixes junos_template ignoring the action directive (#5080)
This updates the junos_template to properly process the action directive when loading the configuration.
This commit is contained in:
parent
9436d013d4
commit
9ed01d0cfd
1 changed files with 20 additions and 7 deletions
|
@ -101,9 +101,11 @@ EXAMPLES = """
|
|||
src: config.j2
|
||||
action: overwrite
|
||||
"""
|
||||
from ansible.module_utils.network import NetworkModule
|
||||
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'
|
||||
|
||||
def main():
|
||||
|
@ -125,24 +127,35 @@ def main():
|
|||
confirm = module.params['confirm']
|
||||
commit = not module.check_mode
|
||||
|
||||
replace = False
|
||||
overwrite = False
|
||||
|
||||
action = module.params['action']
|
||||
if action == 'overwrite':
|
||||
overwrite = True
|
||||
elif action == 'replace':
|
||||
replace = True
|
||||
|
||||
src = module.params['src']
|
||||
fmt = module.params['config_format']
|
||||
|
||||
if action == 'overwrite' and fmt == 'set':
|
||||
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['_backup'] = str(module.config.get_config()).strip()
|
||||
|
||||
diff = module.config.load_config(src, action=action, comment=comment,
|
||||
format=fmt, commit=commit, confirm=confirm)
|
||||
try:
|
||||
diff = module.config.load_config(src, commit=commit, replace=replace,
|
||||
confirm=confirm, comment=comment, config_format=fmt)
|
||||
|
||||
if diff:
|
||||
results['changed'] = True
|
||||
results['diff'] = dict(prepared=diff)
|
||||
if diff:
|
||||
results['changed'] = True
|
||||
results['diff'] = dict(prepared=diff)
|
||||
except NetworkError:
|
||||
exc = get_exception()
|
||||
module.fail_json(msg=str(exc), **exc.kwargs)
|
||||
|
||||
module.exit_json(**results)
|
||||
|
||||
|
|
Loading…
Reference in a new issue