Skip to content

Latest commit

 

History

History
238 lines (204 loc) · 10.2 KB

ansible.yang.get_module.rst

File metadata and controls

238 lines (204 loc) · 10.2 KB

ansible.yang.get

Fetch the device configuration and render it in JSON format defined by RFC7951

  • The module will fetch the configuration data for a given YANG model and render it in JSON format (as per RFC 7951).

The below requirements are needed on the host that executes this module.

  • ncclient (>=v0.5.2)
  • pyang
  • xsltproc
Parameter Choices/Defaults Comments
file
list / elements=path / required
The file path of the YANG model that corresponds to the configuration fetch from the remote host. This options accepts wildcard (*) as well for the filename in case the configuration requires to parse multiple yang file. For example "openconfig/public/tree/master/release/models/interfaces/*.yang"
filter
string
This argument specifies the XML string which acts as a filter to restrict the portions of the data to be are retrieved from the remote device. If this option is not specified entire configuration or state data is returned in result depending on the value of source option. The filter value can be either XML string or XPath, if the filter is in XPath format the NETCONF server running on remote host should support xpath capability else it will result in an error.
lock
string
    Choices:
  • never ←
  • always
  • if-supported
Instructs the module to explicitly lock the datastore specified as source. If no source is defined, the running datastore will be locked. By setting the option value always is will explicitly lock the datastore mentioned in source option. By setting the option value never it will not lock the source datastore. The value if-supported allows better interworking with NETCONF servers, which do not support the (un)lock operation for all supported datastores.
search_path
path
Default:
"~/.ansible/yang/spec"
is a colon : separated list of directories to search for imported yang modules in the yang file mentioned in path option. If the value is not given it will search in the default directory path.
source
string
    Choices:
  • running
  • candidate
  • startup
This argument specifies the datastore from which configuration data should be fetched. Valid values are running, candidate and startup. If the source value is not set both configuration and state information are returned in response from running datastore.

Note

  • This module requires the NETCONF system service be enabled on the remote device being managed.
  • This module supports the use of connection=ansible.netcommon.netconf
  • To use this module xsltproc should be installed on control node
- name: fetch interface configuration and return it in JSON format
  ansible.yang.get:
    filter: |
      <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"><interface-configuration>
      </interface-configuration></interface-configurations>
    file: "{{ playbook_dir }}/YangModels/yang/tree/master/vendor/cisco/xr/613/*.yang"
    search_path: "{{ playbook_dir }}/YangModels/yang/tree/master/vendor/cisco/xr/613:{{ playbook_dir }}/pyang/modules"

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
json_data
dictionary
always
The running configuration in json format

Sample:
{ "openconfig-interfaces:interfaces": { "interface": [{ "name" : "GigabitEthernet0/0/0/2", "config" : { "name" : "GigabitEthernet0/0/0/2", "description": "configured by Ansible yang collection", "mtu": 1024 } }] } }
xml_data
string
always
The running configuration in xml format

Sample:
<data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"> <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"> <interface-configuration> <active>act</active> <interface-name>GigabitEthernet0/0/0/2</interface-name> <description>configured by Ansible yang collection</description> <mtu>1024</mtu> </interface-configuration> </interface-configurations> </data>


Authors

  • Ganesh Nalawade (@ganeshrn)