community.yang.get (1.1.0) — module

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

Authors: Ganesh Nalawade (@ganeshrn)

This plugin has a corresponding action plugin.

Install collection

Install with ansible-galaxy collection install community.yang:==1.1.0


Add to requirements.yml

  collections:
    - name: community.yang
      version: 1.1.0

Description

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


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: fetch interface configuration and return it in JSON format
  community.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"

Inputs

    
file:
    description:
    - 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"
    elements: path
    required: true
    type: list

lock:
    choices:
    - never
    - always
    - if-supported
    default: never
    description:
    - Instructs the module to explicitly lock the datastore specified as C(source). If
      no I(source) is defined, the I(running) datastore will be locked. By setting the
      option value I(always) is will explicitly lock the datastore mentioned in C(source)
      option. By setting the option value I(never) it will not lock the C(source) datastore.
      The value I(if-supported) allows better interworking with NETCONF servers, which
      do not support the (un)lock operation for all supported datastores.
    type: str

filter:
    description:
    - 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 C(source) option. The C(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.
    type: str

source:
    choices:
    - running
    - candidate
    - startup
    description:
    - This argument specifies the datastore from which configuration data should be fetched.
      Valid values are I(running), I(candidate) and I(startup). If the C(source) value
      is not set both configuration and state information are returned in response from
      running datastore.
    type: str

search_path:
    default: ~/.ansible/yang/spec
    description:
    - is a colon C(:) separated list of directories to search for imported yang modules
      in the yang file mentioned in C(path) option. If the value is not given it will
      search in the default directory path.
    type: path

Outputs

json_data:
  description: The running configuration in json format
  returned: always
  sample: "{\n    \"openconfig-interfaces:interfaces\":\n     {\n        \"interface\"\
    : [{\n            \"name\" : \"GigabitEthernet0/0/0/2\",\n            \"config\"\
    \ : {\n                \"name\" : \"GigabitEthernet0/0/0/2\",\n              \
    \  \"description\": \"configured by Ansible yang collection\",\n             \
    \   \"mtu\": 1024\n            }\n        }]\n     }\n}\n"
  type: dict
xml_data:
  description: The running configuration in xml format
  returned: always
  sample: "<data xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\"\
    >\n  <interface-configurations xmlns=\"http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg\"\
    >\n    <interface-configuration>\n        <active>act</active>\n        <interface-name>GigabitEthernet0/0/0/2</interface-name>\n\
    \        <description>configured by Ansible yang collection</description>\n  \
    \      <mtu>1024</mtu>\n    </interface-configuration>\n  </interface-configurations>\n\
    </data>\n"
  type: str