1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #9 from dgarros/junos_modules

Add support for xml, set and text format for config
This commit is contained in:
Peter Sprygada 2016-04-24 07:42:19 -04:00 committed by Matt Clay
parent 582a5bccc8
commit 9d521aa7e0

View file

@ -35,9 +35,10 @@ options:
- The O(config) argument instructs the fact module to collect - The O(config) argument instructs the fact module to collect
the device configuration. The device configuration is the device configuration. The device configuration is
stored in the I(config) key in the hostvars dictionary. stored in the I(config) key in the hostvars dictionary.
required: true if the configuration is returned in xml, it will also be converted
default: false to json and save into the I(config_json) key in the hostvars dictionary.
choices: ['true', 'false'] required: false
choices: ['xml', 'text', 'set']
requirements: requirements:
- junos-eznc - junos-eznc
notes: notes:
@ -54,7 +55,15 @@ EXAMPLES = """
- name: collect default set of facts and configuration - name: collect default set of facts and configuration
junos_facts: 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 = """ RETURN = """
@ -68,7 +77,7 @@ def main():
""" Main entry point for AnsibleModule """ Main entry point for AnsibleModule
""" """
spec = dict( spec = dict(
config=dict(default=False, type='bool'), config=dict(choices=['xml', 'set', 'text']),
transport=dict(default='netconf', choices=['netconf']) transport=dict(default='netconf', choices=['netconf'])
) )
@ -86,7 +95,13 @@ def main():
facts['version_info'] = dict(facts['version_info']) facts['version_info'] = dict(facts['version_info'])
if module.params['config']: 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 result['ansible_facts'] = facts
module.exit_json(**result) module.exit_json(**result)