Repository: ansible/ansible-modules-core

Issue:
junos_template module does not handle the `overwrite` action correctly
<!--- Verify first that your issue/request is not already reported in GitHub -->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Bug Report
##### COMPONENT NAME

junos_template
##### ANSIBLE VERSION

```
ansible 2.2.0 (detached HEAD d98bd3551e) last updated 2016/05/06 18:06:05 (GMT +100)
  lib/ansible/modules/core: (detached HEAD 1f5cf669dd) last updated 2016/05/06 18:06:07 (GMT +100)
  lib/ansible/modules/extras: (detached HEAD 431591c2b4) last updated 2016/05/06 18:06:07 (GMT +100)
```
##### OS / ENVIRONMENT

N/A
##### SUMMARY

The argument parsing for the `junos_template` module is flawed.
If `overwrite=true` is set, `action==merge` as `merge` defaults to `True`
Trying to set `merge=false` as well, gives `FAILED! => {"changed": false, "failed": true, "msg": "parameters are mutually exclusive: ('merge', 'overwrite')"}`

If you set `merge=false`, `action==replace`.

It's impossible to get `action==overwrite`
##### STEPS TO REPRODUCE

```

---
- name: Install configuration
  junos_template: >
    host='{{ ansible_host }}'
    port={{ ansible_port }}
    src='{{ junos_conf }}'
    comment='configured by ansible'
    timeout=120
    overwrite=true

```
##### EXPECTED RESULTS

The config is replaced in it's entirety
##### ACTUAL RESULTS

The config is merged

```
<!--- Paste verbatim command output between quotes -->
```



Discussion:

Resolving patch:
diff --git a/network/junos/junos_template.py b/network/junos/junos_template.py
--- a/network/junos/junos_template.py
+++ b/network/junos/junos_template.py
@@ -62,22 +62,13 @@
         is set to False, this argument is silently ignored.
     required: false
     default: configured by junos_template
-  merge:
+  action:
     description:
-      - The C(merge) argument instructs the module to merge the contents
-        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.
+      - The C(action) argument specifies how the module will apply changes.
     required: false
-    default: true
-  overwrite:
-    description:
-      - 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
+    default: merge
+    choices: ['merge', 'overwrite', 'replace']
+    version_added: "2.2"
   config_format:
     description:
       - The C(format) argument specifies the format of the configuration
@@ -103,11 +94,11 @@
 
 - name: replace config hierarchy
     src: config.j2
-    replace: yes
+    action: replace
 
 - name: overwrite the config
     src: config.j2
-    overwrite: yes
+    action: overwrite
 """
 
 DEFAULT_COMMENT = 'configured by junos_template'
@@ -118,40 +109,28 @@ def main():
         src=dict(required=True, type='path'),
         confirm=dict(default=0, type='int'),
         comment=dict(default=DEFAULT_COMMENT),
-        merge=dict(default=True, type='bool'),
-        overwrite=dict(default=False, type='bool'),
+        action=dict(default='merge', choices=['merge', 'overwrite', 'replace']),
         config_format=dict(choices=['text', 'set', 'xml']),
         backup=dict(default=False, type='bool'),
         transport=dict(default='netconf', choices=['netconf'])
     )
 
-    mutually_exclusive = [('merge', 'overwrite')]
-
     module = get_module(argument_spec=argument_spec,
-                        mutually_exclusive=mutually_exclusive,
                         supports_check_mode=True)
 
     comment = module.params['comment']
     confirm = module.params['confirm']
     commit = not module.check_mode
 
-    merge = module.params['merge']
-    overwrite = module.params['overwrite']
+    action = module.params['action']
 
     src = module.params['src']
     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 "
             "set per junos documentation")
 
-    if merge:
-        action = 'merge'
-    elif overwrite:
-        action = 'overwrite'
-    else:
-        action = 'replace'
-
     results = dict(changed=False)
     results['_backup'] = str(module.get_config()).strip()
 


Test patch: