Repository: ansible/ansible

Issue:
Ansible network module junos_config update: overwrite issue
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
Ansible network module / Junos -> junos_config 

##### ANSIBLE VERSION
```
ansible 2.4.0 (devel 6318229bc4) last updated 2017/03/22 14:22:28 (GMT +000)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/ansible/library']
  python version = 2.7.13 (default, Dec 20 2016, 16:33:50) [GCC 6.2.1 20160822]

```
##### CONFIGURATION

##### OS / ENVIRONMENT
Alpine linux edge running as a docker container.

##### SUMMARY
Issue with :
junos_config with update argument set to "overwrite" and src_format argument set to "set": 
junos_config with update argument set to "overwrite" and src_format argument set to "text":
junos_config with backup argument set to "yes",

##### STEPS TO REPRODUCE
```yaml

With src_format argument set to "set" value

    - name: load configure file into device using file "/ansible-vanilla-config-set/{{ ansible_ssh_host }}"
      junos_config:
        update: overwrite
        src: "/ansible-vanilla-config-set/{{ ansible_ssh_host }}"
        src_format: set
        backup: yes
        comment: update config
        host: "{{ ansible_ssh_host }}"
        username: "{{ juniper_user }}"
        password: "{{ juniper_passwd }}"


With src_format argument set to "text" value

    - name: load configure file into device using file "/ansible-vanilla-config-set/{{ ansible_ssh_host }}"
      junos_config:
        update: overwrite
        src: "/ansible-vanilla-config-set/{{ ansible_ssh_host }}"
        src_format: text
        backup: yes
        comment: update config
        host: "{{ ansible_ssh_host }}"
        username: "{{ juniper_user }}"
        password: "{{ juniper_passwd }}"
```
With src_format set to "text" value and a Junos text configuration format the playbook report:
TASK [load configure file into device using file "/ansible-vanilla-config-set/10.134.250.35"] ***
task path: /ansible-playbook-dir/pb-nmaas-lab-init.yml:32
fatal: [gn4-net-core-5]: FAILED! => {"changed": false, "failed": true, "msg": "invalid action format text"}
        to retry, use: --limit @/ansible-playbook-dir/pb-nmaas-lab-init.retry
 
##### EXPECTED RESULTS
junos_config with update argument set to overwrite and srf_format set to "set" or "text" value.
The configuration should be overwritten as per the documentation description.

##### ACTUAL RESULTS
junos_config with update argument set to "overwrite" and src_format argument set to "set": 
the Junos configuration using "set" format is not entireley replaced as per the behaviour described by the module documentation. The config seems to be  merged.

junos_config with update argument set to "overwrite" and src_format argument set to "text":
the Junos configuration using "text" format is not replaced and the playbook throw the following error: 
fatal: [gn4-net-core-5]: FAILED! => {"changed": false, "failed": true, "msg": "invalid action format text"}

junos_config with backup argument set to "yes", systematically delete backup folder and all files inside this backup. Meaning that all previous backup done by running the plabook are lost. It would be great to chose the name of the path of the backup folder but also avoid to delete recursively thos folder.



Discussion:
cc @Qalthos @ganeshrn
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@Qalthos @ganeshrn is this a 2.3 blocker?
@frederic-loui Can you please try with `update: override` in your playbook. 
Hi,

you mean use "override" instead of "overwrite".
I'm interested in using "overwrite" as per the behaviour described in the
dcumentation.

But I'll test it and get back to you as soon as possible.

All the best,
Frederic

2017-04-04 13:46 GMT+02:00 Ganesh Nalawade <notifications@github.com>:

> @frederic-loui <https://github.com/frederic-loui> Can you please try with update:
> override in your playbook.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/ansible/ansible/issues/22880#issuecomment-291475736>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AJMXBwefAKYdQE4C9tRzEt07XcoSC5LLks5rsi2ugaJpZM4MlY2h>
> .
>


Resolving patch:
diff --git a/lib/ansible/modules/network/junos/junos_config.py b/lib/ansible/modules/network/junos/junos_config.py
--- a/lib/ansible/modules/network/junos/junos_config.py
+++ b/lib/ansible/modules/network/junos/junos_config.py
@@ -129,13 +129,13 @@
         candidate configuration. If statements in the loaded configuration
         conflict with statements in the candidate configuration, the loaded
         statements replace the candidate ones.
-        C(overwrite) discards the entire candidate configuration and replaces
+        C(override) discards the entire candidate configuration and replaces
         it with the loaded configuration.
         C(replace) substitutes each hierarchy level in the loaded configuration
         for the corresponding level.
     required: false
     default: merge
-    choices: ['merge', 'overwrite', 'replace']
+    choices: ['merge', 'override', 'replace']
     version_added: "2.3"
 requirements:
   - junos-eznc
@@ -276,7 +276,7 @@ def main():
         src_format=dict(choices=['xml', 'text', 'set', 'json']),
 
         # update operations
-        update=dict(default='merge', choices=['merge', 'overwrite', 'replace', 'update']),
+        update=dict(default='merge', choices=['merge', 'override', 'replace', 'update']),
 
         # deprecated replace in Ansible 2.3
         replace=dict(type='bool'),


Test patch: