Repository: ansible/ansible

Issue:
junos_facts get remote config in JSON
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
junos_facts

##### ANSIBLE VERSION
```
ansible 2.3.0.0
  config file = /mnt/hgfs/USERNAME/git/net-ops/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]

ansible 2.4.0 (devel f9b4499082) last updated 2017/05/15 08:35:53 (GMT +1300)
  config file = /mnt/hgfs/USERNAME/git/net-ops/ansible.cfg
  configured module search path = [u'/home/USERNAME/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/USERNAME/ansible/lib/ansible
  executable location = /home/USERNAME/ansible/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
Ubuntu 14.04 (2.3.0.0-1 deb package, 2.4.0 git devel)
MacOS Sierra 10.12.4 (brew 2.3.0.0)

##### SUMMARY
Obtain copy of Junos Config in JSON

##### STEPS TO REPRODUCE
Invoke junos_facts with gather_subset: config and config_format set to json

```yaml
 - hosts: av-gw-srs
   connection: local
   gather_facts: no

   vars_prompt:
   - name: "ldap_pw"
     prompt: "LDAP Password"
     private: yes

   vars:
   - netconf:
       password: "{{ ldap_pw }}"
       timeout: 300

   tasks:
   - name: Gather remote facts
     junos_facts:
       provider: "{{ netconf }}"
       gather_subset: config
       config_format: json
```

##### EXPECTED RESULTS
ansible_net_config be populated with the json config from the remote juniper that can be parsed by jinja2, similar to config_json in 2.2.*

##### ACTUAL RESULTS
ansible_net_config is an empty string
```
TASK [Gather remote facts] **********************************************************************************************************************************************************
task path: /home/<<USERNAME>>/mac/git/net-ops/playbooks/debug_remote.yml:39
<<<JUNOSHOSTNAME>>> using connection plugin netconf
<<<JUNOSHOSTNAME>>> socket_path: /home/<<USERNAME>>/.ansible/pc/e237c9b826
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/basic.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/junos.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/netconf.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/six/__init__.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/_text.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/pycompat24.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/connection.py
Using module_utils file /home/<<USERNAME>>/ansible/lib/ansible/module_utils/six/_six.py
Using module file /home/<<USERNAME>>/ansible/lib/ansible/modules/network/junos/junos_facts.py
<<<JUNOSHOSTNAME>>> ESTABLISH LOCAL CONNECTION FOR USER: <<USERNAME>>
<<<JUNOSHOSTNAME>>> EXEC /bin/sh -c 'echo ~ && sleep 0'
<<<JUNOSHOSTNAME>>> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494802029.72-175491273595902 `" && echo ansible-tmp-1494802029.72-175491273595902="` echo /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494802029.72-175491273595902 `" ) && sleep 0'
<<<JUNOSHOSTNAME>>> PUT /tmp/tmpSBNPUH TO /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494802029.72-175491273595902/junos_facts.py
<<<JUNOSHOSTNAME>>> EXEC /bin/sh -c 'chmod u+x /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494802029.72-175491273595902/ /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494802029.72-175491273595902/junos_facts.py && sleep 0'
<<<JUNOSHOSTNAME>>> EXEC /bin/sh -c '/usr/bin/python /home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494802029.72-175491273595902/junos_facts.py; rm -rf "/home/<<USERNAME>>/.ansible/tmp/ansible-tmp-1494802029.72-175491273595902/" > /dev/null 2>&1 && sleep 0'
ok: [<<JUNOSHOSTNAME>>] => {
    "ansible_facts": {
        "ansible_net_config": "",
        "ansible_net_gather_subset": [
            "default",
            "config"
        ],
        "ansible_net_hostname": "<<JUNOSHOSTNAME>>",
        "ansible_net_model": "srx240h2",
        "ansible_net_serialnum": "<<SERIAL>>",
        "ansible_net_version": null
    },
    "changed": false,
    "invocation": {
        "module_args": {
            "config_format": "json",
            "gather_subset": [
                "config"
            ],
            "host": null,
            "password": null,
            "port": null,
            "provider": {
                "host": null,
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "port": null,
                "ssh_keyfile": null,
                "timeout": 300,
                "transport": null,
                "username": "<<USERNAME>>"
            },
            "ssh_keyfile": null,
            "timeout": 10,
            "transport": null,
            "username": null
        }
    }
}
META: ran handlers
META: ran handlers
```

config_format: xml and config_format: text both work as expected



Discussion:
cc @Qalthos @ganeshrn
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@JLSNZ What is the version of `junos` running on the device?


@ganeshrn Tested against more devices, and did find a version related issue, JSON however was returned for all of these versions in 2.2.0.0

Test 1: Fail no JSON
Model: srx240h
JUNOS Software Release [12.1X46-D65.4] <- Recommended Junos Release for model

Test 2: Fail no JSON
Model: srx240h2
JUNOS Software Release [12.3X48-D40.5] <- Recommended Junos Release for model

Test 3: JSON Returned
Model: srx345
Junos: 15.1X49-D50.3
JUNOS Software Release [15.1X49-D50.3] <- A few sub versions behind recommended (D75)
In 2.3 it was decided to render the output format that is supported by device natively.
Hence the difference in behavior. 
@gundalow I think this needs to be added as a note in documentation. Thoughts?
@ganeshrn Yup, this needs documenting, perhaps under both the`format:` and `notes:` section

Resolving patch:
diff --git a/lib/ansible/modules/network/junos/junos_facts.py b/lib/ansible/modules/network/junos/junos_facts.py
--- a/lib/ansible/modules/network/junos/junos_facts.py
+++ b/lib/ansible/modules/network/junos/junos_facts.py
@@ -51,10 +51,15 @@
       - The I(config_format) argument specifies the format of the configuration
          when serializing output from the device. This argument is applicable
          only when C(config) value is present in I(gather_subset).
+         The I(config_format) should be supported by the junos version running on
+         device.
     required: false
     default: text
     choices: ['xml', 'set', 'text', 'json']
     version_added: "2.3"
+notes:
+  - Ensure I(config_format) used to retrieve configuration from device
+    is supported by junos version running on device.
 """
 
 EXAMPLES = """


Test patch: