From 9d521aa7e0d82a8ca99ef55347ba219a4d645613 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sun, 24 Apr 2016 07:42:19 -0400 Subject: [PATCH] Merge pull request #9 from dgarros/junos_modules Add support for xml, set and text format for config --- .../modules/network/junos/junos_facts.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/network/junos/junos_facts.py b/lib/ansible/modules/network/junos/junos_facts.py index ac54c7db2b..1e4bc36998 100644 --- a/lib/ansible/modules/network/junos/junos_facts.py +++ b/lib/ansible/modules/network/junos/junos_facts.py @@ -35,9 +35,10 @@ options: - The O(config) argument instructs the fact module to collect the device configuration. The device configuration is stored in the I(config) key in the hostvars dictionary. - required: true - default: false - choices: ['true', 'false'] + if the configuration is returned in xml, it will also be converted + to json and save into the I(config_json) key in the hostvars dictionary. + required: false + choices: ['xml', 'text', 'set'] requirements: - junos-eznc notes: @@ -54,7 +55,15 @@ EXAMPLES = """ - name: collect default set of facts and configuration junos_facts: - config: yes + config: text + +- name: collect default set of facts and configuration in set format + junos_facts: + config: set + +- name: collect default set of facts and configuration in XML and JSON format + junos_facts: + config: xml """ RETURN = """ @@ -68,7 +77,7 @@ def main(): """ Main entry point for AnsibleModule """ spec = dict( - config=dict(default=False, type='bool'), + config=dict(choices=['xml', 'set', 'text']), transport=dict(default='netconf', choices=['netconf']) ) @@ -86,7 +95,13 @@ def main(): facts['version_info'] = dict(facts['version_info']) if module.params['config']: - facts['config'] = module.get_config() + resp_config = module.get_config( config_format=module.params['config']) + + if module.params['config'] == "text" or module.params['config'] == "set": + facts['config'] = resp_config + elif module.params['config'] == "xml": + facts['config'] = xml_to_string(resp_config) + facts['config_json'] = xml_to_json(resp_config) result['ansible_facts'] = facts module.exit_json(**result)