Repository: ansible/ansible

Issue:
junso_config fails if 'src' contains set format
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
junos_config
##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
2.3
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->

##### SUMMARY
<!--- Explain the problem briefly -->

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
---
- name: setup
  hosts: junos_mx
  connection: local
  tasks:
  - name: "junos_mx"
    junos_config:
      host: junos_mx
      username: "xxx"
      password: "xxx"
      backup: yes
      src: config.set
```
```
#cat config.set
set interfaces ge-0/0/8 unit 0 description "abc"
delete interfaces ge-0/0/7
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
fatal: [junos_mx]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "backup": true, 
            "comment": "configured by junos_config", 
            "confirm": 0, 
            "host": "junos_mx", 
            "lines": null, 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "port": null, 
            "provider": null, 
            "replace": null, 
            "rollback": null, 
            "src": "set interfaces ge-0/0/8 unit 0 description \"abc\"\ndelete interfaces ge-0/0/7\n", 
            "src_format": null, 
            "ssh_keyfile": null, 
            "timeout": 10, 
            "transport": null, 
            "update": "merge", 
            "username": "root", 
            "zeroize": false
        }
    }, 
    "msg": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><rpc-error xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns:junos=\"http://xml.juniper.net/junos/12.1R1/junos\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n<error-severity>error</error-severity>\n<error-info>\n<bad-element>set</bad-element>\n</error-info>\n<error-message>syntax error</error-message>\n</rpc-error>\n"
}

```



Discussion:
cc @Qalthos
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

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
@@ -234,8 +234,6 @@ def filter_delete_statements(module, candidate):
 
 def configure_device(module, warnings):
     candidate = module.params['lines'] or module.params['src']
-    if isinstance(candidate, string_types):
-        candidate = candidate.split('\n')
 
     kwargs = {
         'comment': module.params['comment'],
@@ -257,6 +255,9 @@ def configure_device(module, warnings):
         else:
             kwargs.update({'format': config_format, 'action': module.params['update']})
 
+    if isinstance(candidate, string_types):
+        candidate = candidate.split('\n')
+
     # this is done to filter out `delete ...` statements which map to
     # nothing in the config as that will cause an exception to be raised
     if any((module.params['lines'], config_format == 'set')):


Test patch: