community.yang.xml2json (1.1.0) — lookup

Converts xml input to json structure output by mapping it against corresponding Yang model

Authors: Ganesh Nalawade (@ganeshrn)

Install collection

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

Add to requirements.yml

    - name: community.yang
      version: 1.1.0


This plugin lookups the input xml data, typically Netconf rpc response received from remote host and convert it to json format as defined by RFC 7951 JSON Encoding of Data Modeled with YANG

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: translate json to xml
  debug: msg="{{ lookup('community.yang.xml2json', interfaces_config.xml,
                         search_path='openconfig/public/release/models:pyang/modules/') }}"


    - Input xml file path that adheres to a given yang model. This can be a Netconf/Restconf
      xml rpc response that contains operational and configuration data received from
      remote host.
    required: true
    type: path

    - Path to yang model file against which the xml file is validated and converted to
      json as per json encoding of data modeled with YANG.
    required: true
    type: path

    - This option 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 current directory.
    required: false

    default: false
    - This is a boolean flag to indicate if the intermediate files generated while validation
      json configuration should be kept or deleted. If the value is C(true) the files
      will not be deleted else by default all the intermediate files will be deleted irrespective
      of whether task run is successful or not. The intermediate files are stored in path
      C(~/.ansible/tmp/json2xml), this option is mainly used for debugging purpose.
    type: bool


  description: The translated json structure from xml