From 9ed01d0cfdeab541b3600c12359508b21a1a67ac Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Wed, 28 Sep 2016 14:26:25 -0400 Subject: [PATCH] fixes junos_template ignoring the action directive (#5080) This updates the junos_template to properly process the action directive when loading the configuration. --- .../modules/network/junos/_junos_template.py | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/network/junos/_junos_template.py b/lib/ansible/modules/network/junos/_junos_template.py index 30dac995787..c65525d8491 100644 --- a/lib/ansible/modules/network/junos/_junos_template.py +++ b/lib/ansible/modules/network/junos/_junos_template.py @@ -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)