ansible.netcommon.netconf_config – netconf device configuration
ansible.netcommon.netconf_config – netconf device configuration
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_config
.
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 send a configuration XML file to a netconf device, and detects if there was a configuration change.
Requirements
The below requirements are needed on the host that executes this module.
- ncclient
Parameters
Parameter | Choices/Defaults | Comments | |
---|---|---|---|
backup boolean |
|
This argument will cause the module to create a full backup of the current | |
backup_options dictionary |
This is a dict object containing configurable options related to backup file path. The value of this option is read only when | ||
dir_path path |
This option provides the path ending with directory name in which the backup configuration file will be stored. If the directory does not exist it will be first created and the filename is either the value of | ||
filename string |
The filename to be used to store the backup configuration. If the filename is not given it will be generated based on the hostname, current time and date in format defined by _config.@ | ||
commit boolean |
|
This boolean flag controls if the configuration changes should be committed or not after editing the candidate datastore. This option is supported only if remote Netconf server supports :candidate capability. If the value is set to False commit won't be issued after edit-config operation and user needs to handle commit or discard-changes explicitly. | |
confirm integer |
Default: 0 |
This argument will configure a timeout value for the commit to be confirmed before it is automatically rolled back. If the | |
confirm_commit boolean |
|
This argument will execute commit operation on remote device. It can be used to confirm a previous commit. | |
content raw |
The configuration data as defined by the device's data models, the value can be either in xml string format or text format or python dictionary representation of JSON format. In case of json string format it will be converted to the corresponding xml string using xmltodict library before pushing onto the remote host. In case the value of this option isn text format the format should be supported by remote Netconf server. If the value of
| ||
default_operation string |
|
The default operation for rpc, valid values are merge, replace and none. If the default value is merge, the configuration data in the | |
delete boolean |
|
It instructs the module to delete the configuration from value mentioned in | |
error_option string |
|
This option controls the netconf server action after an error occurs while editing the configuration. If error_option=stop-on-error, abort the config edit on first error. If error_option=continue-on-error, continue to process configuration data on error. The error is recorded and negative response is generated if any errors occur. If error_option=rollback-on-error, rollback to the original configuration if any error occurs. This requires the remote Netconf server to support the error_option=rollback-on-error capability. | |
format string |
|
The format of the configuration provided as value of In case of json string format it will be converted to the corresponding xml string using xmltodict library before pushing onto the remote host. In case of text format of the configuration should be supported by remote Netconf server. If the value of If the data format is not identified it is set to xml by default. | |
get_filter raw |
This argument specifies the XML string which acts as a filter to restrict the portions of the data retrieved from the remote device when comparing the before and after state of the device following calls to edit_config. When not specified, the entire configuration or state data is returned for comparison depending on the value of | ||
host string |
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport. | ||
hostkey_verify boolean |
|
If set to | |
lock string |
|
Instructs the module to explicitly lock the datastore specified as | |
look_for_keys boolean |
|
Enables looking in the usual locations for the ssh keys (e.g. :file:`~/.ssh/id_*`) | |
password string |
Specifies the password to use to authenticate the connection to the remote device. This value is used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable | ||
port integer |
Default: 830 |
Specifies the port to use when building the connection to the remote device. The port value will default to port 830. | |
save boolean |
|
The | |
source_datastore string |
Name of the configuration datastore to use as the source to copy the configuration to the datastore mentioned by
| ||
src path |
Specifies the source path to the xml file that contains the configuration or configuration template to load. The path to the source file can either be the full path on the Ansible control host or a relative path from the playbook or role root directory. This argument is mutually exclusive with xml. | ||
ssh_keyfile path |
Specifies the SSH key to use to authenticate the connection to the remote device. This value is the path to the key used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable | ||
target string |
|
Name of the configuration datastore to be edited. - auto, uses candidate and fallback to running - candidate, edit datastore and then commit - running, edit datastore directly
| |
timeout integer |
Default: 10 |
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error. | |
username string |
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable | ||
validate boolean |
|
This boolean flag if set validates the content of datastore given in |
Notes
Note
- This module requires the netconf system service be enabled on the remote device being managed.
- This module supports devices with and without the candidate and confirmed-commit capabilities. It will always use the safer feature.
- This module supports the use of connection=netconf
- For information on using netconf see the Platform Options guide using Netconf
- For more information on using Ansible to manage network devices see the Ansible Network Guide
- This module is supported on
ansible_network_os
network platforms. See the Network Platform Options for details.
Examples
- name: use lookup filter to provide xml configuration
ansible.netcommon.netconf_config:
content: "{{ lookup('file', './config.xml') }}"
- name: set ntp server in the device
ansible.netcommon.netconf_config:
content: |
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
<system xmlns="urn:ietf:params:xml:ns:yang:ietf-system">
<ntp>
<enabled>true</enabled>
<server>
<name>ntp1</name>
<udp><address>127.0.0.1</address></udp>
</server>
</ntp>
</system>
</config>
- name: wipe ntp configuration
ansible.netcommon.netconf_config:
content: |
<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
<system xmlns="urn:ietf:params:xml:ns:yang:ietf-system">
<ntp>
<enabled>false</enabled>
<server operation="remove">
<name>ntp1</name>
</server>
</ntp>
</system>
</config>
- name: configure interface while providing different private key file path (for connection=netconf)
ansible.netcommon.netconf_config:
backup: yes
register: backup_junos_location
vars:
ansible_private_key_file: /home/admin/.ssh/newprivatekeyfile
- name: configurable backup path
ansible.netcommon.netconf_config:
backup: yes
backup_options:
filename: backup.cfg
dir_path: /home/user
- name: "configure using direct native format configuration (cisco iosxr)"
ansible.netcommon.netconf_config:
format: json
content: {
"config": {
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": {
"active": "act",
"description": "test for ansible Loopback999",
"interface-name": "Loopback999"
}
}
}
}
get_filter: {
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null
}
}
- name: "configure using json string format configuration (cisco iosxr)"
ansible.netcommon.netconf_config:
format: json
content: |
{
"config": {
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": {
"active": "act",
"description": "test for ansible Loopback999",
"interface-name": "Loopback999"
}
}
}
}
get_filter: |
{
"interface-configurations": {
"@xmlns": "http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg",
"interface-configuration": null
}
}
# 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:
Key | Returned | Description |
---|---|---|
backup_path string |
when backup is yes |
The full path to the backup file
Sample: /playbooks/ansible/backup/config.2016-07-16@22:28:34 |
diff dictionary |
when diff is enabled |
If --diff option in enabled while running, the before and after configuration change are returned as part of before and after key.
Sample: {'after': ' 17.3R1.10...', 'before': ' 17.3R1.10...'} |
server_capabilities list / elements=string |
success |
list of capabilities of the server
Sample: |
Authors
- Leandro Lisboa Penz (@lpenz)
- Ganesh Nalawade (@ganeshrn)
© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.11/collections/ansible/netcommon/netconf_config_module.html