This repo hosts the ansible.yang
Ansible Collection.
The collection includes the ansible plugins to help the support Yang manily with network devices.
This collection has been tested against following Ansible versions: >=2.9.10.
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 Community 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 Community 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
- name: community.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.
The 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 </path/to/inventory> <tests_to_run>:
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:
- Update
galaxy.yml
and this README'srequirements.yml
example with the newversion
for the collection. - Update the CHANGELOG:
1. Make sure you have
antsibull-changelog
installed. 2. Make sure there are fragments for all known changes inchangelogs/fragments
. 3. Runantsibull-changelog release
. - Commit the changes and create a PR with the changes. Wait for tests to pass, then merge it once they have.
- Tag the version in Git and push to GitHub.
After the version is published, verify it exists on the Ansible Yang Community Collection Galaxy page.
- Ansible Using collections for more details.
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:
- IRC - the
#ansible-network
libera.chat channel - Slack - https://ansiblenetwork.slack.com
See the Ansible Community Guide for details on contributing to Ansible.
- Ansible Collection overview
- Ansible User guide
- Ansible Developer guide
- Ansible Community code of conduct
GNU General Public License v3.0 or later.
See LICENSE to see the full text.