ansible.netcommon.netconf_get – Fetch configuration/state data from NETCONF enabled network devices.¶
Note
This plugin is part of the ansible.netcommon collection (version 1.5.0).
To install it use: ansible-galaxy collection install ansible.netcommon
.
To use it in a playbook, specify: ansible.netcommon.netconf_get
.
New in version 1.0.0: of ansible.netcommon
Synopsis¶
NETCONF is a network management protocol developed and standardized by the IETF. It is documented in RFC 6241.
This module allows the user to fetch configuration and state data from NETCONF enabled network devices.
Requirements¶
The below requirements are needed on the host that executes this module.
ncclient (>=v0.5.2)
jxmlease (for display=json)
xmltodict (for display=native)
Parameters¶
Notes¶
Note
This module requires the NETCONF system service be enabled on the remote device being managed.
This module supports the use of connection=netconf
This module is supported on
ansible_network_os
network platforms. See the Network Platform Options for details.
Examples¶
- name: Get running configuration and state data
ansible.netcommon.netconf_get:
- name: Get configuration and state data from startup datastore
ansible.netcommon.netconf_get:
source: startup
- name: Get system configuration data from running datastore state (junos)
ansible.netcommon.netconf_get:
source: running
filter: <configuration><system></system></configuration>
- name: Get configuration and state data in JSON format
ansible.netcommon.netconf_get:
display: json
- name: get schema list using subtree w/ namespaces
ansible.netcommon.netconf_get:
display: json
filter: <netconf-state xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"><schemas><schema/></schemas></netconf-state>
lock: never
- name: get schema list using xpath
ansible.netcommon.netconf_get:
display: xml
filter: /netconf-state/schemas/schema
- name: get interface configuration with filter (iosxr)
ansible.netcommon.netconf_get:
display: pretty
filter: <interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"></interface-configurations>
lock: if-supported
- name: Get system configuration data from running datastore state (junos)
ansible.netcommon.netconf_get:
source: running
filter: <configuration><system></system></configuration>
lock: if-supported
- name: Get complete configuration data from running datastore (SROS)
ansible.netcommon.netconf_get:
source: running
filter: <configure xmlns="urn:nokia.com:sros:ns:yang:sr:conf"/>
- name: Get complete state data (SROS)
ansible.netcommon.netconf_get:
filter: <state xmlns="urn:nokia.com:sros:ns:yang:sr:state"/>
- name: "get configuration with json filter string and native output (using xmltodict)"
netconf_get:
filter: |
{
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null
}
}
display: native
- name: Define the Cisco IOSXR interface filter
set_fact:
filter:
interface-configurations:
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg"
interface-configuration: null
- name: "get configuration with native filter type using set_facts"
ansible.netcommon.netconf_get:
filter: "{{ filter }}"
display: native
register: result
- name: "get configuration with direct native filter type"
ansible.netcommon.netconf_get:
filter: {
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null
}
}
display: native
register: result
# Make a round-trip interface description change, diff the before and after
# this demonstrates the use of the native display format and several utilities
# from the ansible.utils collection
- name: Define the openconfig interface filter
set_fact:
filter:
interfaces:
"@xmlns": "http://openconfig.net/yang/interfaces"
interface:
name: Ethernet2
- name: Get the pre-change config using the filter
ansible.netcommon.netconf_get:
source: running
filter: "{{ filter }}"
display: native
register: pre
- name: Update the description
ansible.utils.update_fact:
updates:
- path: pre.output.data.interfaces.interface.config.description
value: "Configured by ansible {{ 100 | random }}"
register: updated
- name: Apply the new configuration
ansible.netcommon.netconf_config:
content:
config:
interfaces: "{{ updated.pre.output.data.interfaces }}"
- name: Get the post-change config using the filter
ansible.netcommon.netconf_get:
source: running
filter: "{{ filter }}"
display: native
register: post
- name: Show the differences between the pre and post configurations
ansible.utils.fact_diff:
before: "{{ pre.output.data|ansible.utils.to_paths }}"
after: "{{ post.output.data|ansible.utils.to_paths }}"
# TASK [Show the differences between the pre and post configurations] ********
# --- before
# +++ after
# @@ -1,11 +1,11 @@
# {
# - "@time-modified": "2020-10-23T12:27:17.462332477Z",
# + "@time-modified": "2020-10-23T12:27:21.744541708Z",
# "@xmlns": "urn:ietf:params:xml:ns:netconf:base:1.0",
# "interfaces.interface.aggregation.config['fallback-timeout']['#text']": "90",
# "interfaces.interface.aggregation.config['fallback-timeout']['@xmlns']": "http://arista.com/yang/openconfig/interfaces/augments",
# "interfaces.interface.aggregation.config['min-links']": "0",
# "interfaces.interface.aggregation['@xmlns']": "http://openconfig.net/yang/interfaces/aggregate",
# - "interfaces.interface.config.description": "Configured by ansible 56",
# + "interfaces.interface.config.description": "Configured by ansible 67",
# "interfaces.interface.config.enabled": "true",
# "interfaces.interface.config.mtu": "0",
# "interfaces.interface.config.name": "Ethernet2",
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Authors¶
Ganesh Nalawade (@ganeshrn)
Sven Wisotzky (@wisotzky)