adds config_format argument to the facts module
this change adds config_format argument with choices of xml, set or text to specify the desired format of the config returned from the remote device. The default value is text
This commit is contained in:
parent
c41cb48007
commit
a6dc526570
1 changed files with 27 additions and 12 deletions
|
@ -32,12 +32,23 @@ extends_documentation_fragment: junos
|
||||||
options:
|
options:
|
||||||
config:
|
config:
|
||||||
description:
|
description:
|
||||||
- The O(config) argument instructs the fact module to collect
|
- The C(config) argument instructs the fact module to collect
|
||||||
the device configuration. The device configuration is
|
the configuration from the remote device. The configuration
|
||||||
stored in the I(config) key in the hostvars dictionary.
|
is then included in return facts. By default, the configuration
|
||||||
if the configuration is returned in xml, it will also be converted
|
is returned as text. The C(config_format) can be used to return
|
||||||
to json and save into the I(config_json) key in the hostvars dictionary.
|
different Junos configuration formats.
|
||||||
|
required: true
|
||||||
|
default: false
|
||||||
|
config_format:
|
||||||
|
description:
|
||||||
|
- The C(config_format) argument is used to specify the desired
|
||||||
|
format of the configuration file. Devices support three
|
||||||
|
configuration file formats. By default, the configuration
|
||||||
|
from the device is returned as text. The other options include
|
||||||
|
set and xml. If the xml option is choosen, the configuration file
|
||||||
|
is returned as both xml and json.
|
||||||
required: false
|
required: false
|
||||||
|
default: text
|
||||||
choices: ['xml', 'text', 'set']
|
choices: ['xml', 'text', 'set']
|
||||||
requirements:
|
requirements:
|
||||||
- junos-eznc
|
- junos-eznc
|
||||||
|
@ -55,15 +66,17 @@ EXAMPLES = """
|
||||||
|
|
||||||
- name: collect default set of facts and configuration
|
- name: collect default set of facts and configuration
|
||||||
junos_facts:
|
junos_facts:
|
||||||
config: text
|
config: yes
|
||||||
|
|
||||||
- name: collect default set of facts and configuration in set format
|
- name: collect default set of facts and configuration in set format
|
||||||
junos_facts:
|
junos_facts:
|
||||||
config: set
|
config: yes
|
||||||
|
config_format: set
|
||||||
|
|
||||||
- name: collect default set of facts and configuration in XML and JSON format
|
- name: collect default set of facts and configuration in XML and JSON format
|
||||||
junos_facts:
|
junos_facts:
|
||||||
config: xml
|
config: yes
|
||||||
|
config_format: xml
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RETURN = """
|
RETURN = """
|
||||||
|
@ -77,7 +90,8 @@ def main():
|
||||||
""" Main entry point for AnsibleModule
|
""" Main entry point for AnsibleModule
|
||||||
"""
|
"""
|
||||||
spec = dict(
|
spec = dict(
|
||||||
config=dict(choices=['xml', 'set', 'text']),
|
config=dict(required=True, type='bool'),
|
||||||
|
config_format=dict(default='text', choices=['xml', 'set', 'text']),
|
||||||
transport=dict(default='netconf', choices=['netconf'])
|
transport=dict(default='netconf', choices=['netconf'])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -95,11 +109,12 @@ def main():
|
||||||
facts['version_info'] = dict(facts['version_info'])
|
facts['version_info'] = dict(facts['version_info'])
|
||||||
|
|
||||||
if module.params['config']:
|
if module.params['config']:
|
||||||
resp_config = module.get_config( config_format=module.params['config'])
|
config_format = module.params['config_format']
|
||||||
|
resp_config = module.get_config( config_format=config_format)
|
||||||
|
|
||||||
if module.params['config'] == "text" or module.params['config'] == "set":
|
if config_format in ['text', 'set']:
|
||||||
facts['config'] = resp_config
|
facts['config'] = resp_config
|
||||||
elif module.params['config'] == "xml":
|
elif config_format == "xml":
|
||||||
facts['config'] = xml_to_string(resp_config)
|
facts['config'] = xml_to_string(resp_config)
|
||||||
facts['config_json'] = xml_to_json(resp_config)
|
facts['config_json'] = xml_to_json(resp_config)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue