ansible.netcommon.cli_config – Push text based configuration to network devices over network_cli
Note
This plugin is part of the ansible.netcommon collection (version 2.5.0).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install ansible.netcommon
.
To use it in a playbook, specify: ansible.netcommon.cli_config
.
New in version 1.0.0: of ansible.netcommon
Synopsis
This module provides platform agnostic way of pushing text based configuration to network devices over network_cli connection plugin.
Note
This module has a corresponding action plugin.
Parameters
Parameter |
Comments |
---|---|
This argument will cause the module to create a full backup of the current running config from the remote device before any changes are made. If the Choices:
|
|
This is a dict object containing configurable options related to backup file path. The value of this option is read only when |
|
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 |
|
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 <hostname>_config.<current-date>@<current-time> |
|
The Choices:
|
|
The |
|
The config to be pushed to the network device. This argument is mutually exclusive with |
|
The defaults argument will influence how the running-config is collected from the device. When the value is set to true, the command used to collect the running-config is append with the all keyword. When the value is set to false, the command is issued without the all keyword. Choices:
|
|
Use this argument to specify one or more lines that should be ignored during the diff. This is used for lines in the configuration that are automatically updated by the system. This argument takes a list of regular expressions or exact line matches. Note that this parameter will be ignored if the platform has onbox diff support. |
|
Instructs the module on the way to perform the matching of the set of commands against the current device config. If Choices:
|
|
Instructs the module on the way to perform the configuration on the device. If the Choices:
|
|
This argument is used when pushing a multiline configuration element to the device. It specifies the character to use as the delimiting character. This only applies to the configuration action. |
|
If the |
|
The |
Notes
Note
The commands will be returned only for platforms that do not support onbox diff. The
--diff
option with the playbook will return the difference in configuration for devices that has support for onbox diffTo ensure idempotency and correct diff the configuration lines in the relevant module options should be similar to how they appear if present in the running configuration on device including the indentation.
This module is supported on
ansible_network_os
network platforms. See the Network Platform Options for details.
Examples
- name: configure device with config
ansible.netcommon.cli_config:
config: "{{ lookup('template', 'basic/config.j2') }}"
- name: multiline config
ansible.netcommon.cli_config:
config: |
hostname foo
feature nxapi
- name: configure device with config with defaults enabled
ansible.netcommon.cli_config:
config: "{{ lookup('template', 'basic/config.j2') }}"
defaults: yes
- name: Use diff_match
ansible.netcommon.cli_config:
config: "{{ lookup('file', 'interface_config') }}"
diff_match: none
- name: nxos replace config
ansible.netcommon.cli_config:
replace: bootflash:nxoscfg
- name: junos replace config
ansible.netcommon.cli_config:
replace: /var/home/ansible/junos01.cfg
- name: commit with comment
ansible.netcommon.cli_config:
config: set system host-name foo
commit_comment: this is a test
- name: configurable backup path
ansible.netcommon.cli_config:
config: "{{ lookup('template', 'basic/config.j2') }}"
backup: yes
backup_options:
filename: backup.cfg
dir_path: /home/user
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The full path to the backup file Returned: when backup is yes Sample: “/playbooks/ansible/backup/hostname_config.2016-07-16@22:28:34” |
|
The set of commands that will be pushed to the remote device Returned: When supports_generated_diff=True and supports_onbox_diff=False in the platform’s cliconf plugin Sample: [“interface Loopback999”, “no shutdown”] |
|
The diff generated on the device when the commands were applied Returned: When supports_onbox_diff=True in the platform’s cliconf plugin Sample: “— system:/running-config\n+++ session:/ansible_1599745461-session-config\n@@ -4,7 +4,7 @@\n !\n transceiver qsfp default-mode 4x10G\n !\n-hostname veos\n+hostname veos3\n !\n spanning-tree mode mstp” |
Authors
Trishna Guha (@trishnaguha)