The Red Hat Ecosystem Catalog is the official source for discovering and learning more about the Red Hat Ecosystem of both Red Hat and certified third-party products and services.
We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

4Modules11Plugins1Dependency
Ansible yang collection for yang based operation
This repo hosts the ansible.yang Ansible Collection.
The collection includes the ansible plugins to help support Yang mainly with network devices.
This collection has been tested against following Ansible versions: >=2.14.0.
For collections that support Ansible 2.9, please ensure you update your network_os to use the
fully qualified collection name (for example, cisco.ios.ios).
Plugins and modules within a collection may be tested with only specific Ansible versions.
A collection may contain metadata that identifies these versions.
PEP440 is the schema used to describe the versions of Ansible.
The Ansible yang collection supports netconf connections.
| Name | Description |
|---|---|
| ansible.yang.json2xml | Validates json configuration against yang data model and convert it to xml. |
| ansible.yang.spec | This plugin reads the content of given yang document and generates json and xml configuration skeleton and a tree structure of yang document. |
| ansible.yang.xml2json | Converts xml input to json structure output by mapping it against corresponding Yang model |
| Name | Description |
|---|---|
| ansible.yang.configure | Reads the input configuration in JSON format and pushes to the remote host over netconf |
| ansible.yang.fetch | Fetch given yang model and it's dependencies |
| ansible.yang.generate_spec | Generate JSON/XML schema and tree representation for given YANG model |
| ansible.yang.get | Fetch the device configuration and render it in JSON format defined by RFC7951 |
Before using the Ansible Yang collection, you need to install it with the ansible-galaxy CLI:
ansible-galaxy collection install ansible.yang
You can also include it in a requirements.yml file and install it via ansible-galaxy collection install -r requirements.yml using the format:
---
collections:
- name: ansible.yang
1. Cisco IOSXR 6.1.3
It's preferable to use content in this collection using their Fully Qualified Collection Namespace (FQCN), for example ansible.yang.configure:
---
- hosts: iosxr
gather_facts: false
connection: ansible.netcommon.netconf
tasks:
- name: "Fetch given yang model and all the dependent models from remote host"
ansible.yang.fetch:
name: Cisco-IOS-XR-ifmgr-cfg
- name: get interface configuration in json/xml 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: "./files/cisco/iosxr/*.yang"
search_path: "./files/cisco/iosxr"
register: result
- name: Configure interface description providing json input file
ansible.yang.configure:
config: "{{ lookup('file', config_file) }}"
file: "{{ yang_file }}"
search_path: "{{ search_path }}"
register: result
- name: Configure interface description with json input
ansible.yang.configure:
config:
{
"Cisco-IOS-XR-ifmgr-cfg:interface-configurations": {
"interface-configuration": [
{
"active": "act",
"description": "test for ansible 400",
"interface-name": "Loopback888",
"interface-virtual": [
null
],
"shutdown": [
null
]
},
{
"active": "act",
"description": "This interface is configures with Ansible",
"interface-name": "GigabitEthernet0/0/0/4"
}
]
}
}
file: "{{ yang_file }}"
search_path: "{{ search_path }}"
register: result
- name: generate spec from open-config interface yang model data and represent in xml, json and yang tree
ansible.yang.generate_spec:
file: "{{ spec_yang_file }}"
search_path: "{{ spec_search_path }}"
doctype: config
json_schema:
path: "./output/{{ inventory_hostname }}/openconfig-interfaces-config.json"
defaults: True
xml_schema:
path: "./output/{{ inventory_hostname }}/openconfig-interfaces-config.xml"
defaults: True
annotations: True
tree_schema:
path: "./output/{{ inventory_hostname }}/openconfig-interfaces-config.tree"t
For documentation on how to use individual modules and other content included in this collection, please see the links in the 'Included content' section earlier in this README.
If you want to develop new content for this collection or improve what's already here, the easiest way to work on the collection is to clone it into one of the configured COLLECTIONS_PATHS, and work on it there.
ansible-testThe tests directory contains configuration for running sanity and integration tests using ansible-test.
To run these network integration tests, use ansible-test network-integration --inventory :
ansible-test network-integration --inventory ~/myinventory -vvv <name of the plugin>
Releases are automatically built and pushed to Ansible Galaxy for any new tag. Before tagging a release, make sure to do the following:
galaxy.yml and this README's requirements.yml example with the new version for the collection.antsibull-changelog installed.changelogs/fragments.antsibull-changelog release.After the version is published, verify it exists on the [Ansible Yang Community Collection Galaxy page](https://galaxy.ansible.com/ansible/yang).We welcome community contributions to this collection. If you find problems, please open an issue or create a PR against the Ansible Yang collection repository.
You can also join us on:
#ansible-network libera.chat channelSee the Ansible Community Guide for details on contributing to Ansible.
GNU General Public License v3.0 or later.
See LICENSE to see the full text.
| Product |
|---|
| 2.4 |
This collection requires the following collections for use:
| Name | Summary |
|---|