Skip to content

cli_config

Collection Note

This module is part of the ansible.netcommon collection. To install the collection, use:

ansible-galaxy collection install ansible.netcommon
Added in version 1.0.0.

Synopsis

  • This module provides platform agnostic way of pushing text based configuration to network devices over network_cli connection plugin.

Parameters

Parameter Defaults / Choices Comments
backup
bool
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 C(backup_options) value is not given, the backup file is written to the C(backup) folder in the playbook root directory or role root directory, if playbook is part of an ansible role. If the directory does not exist, it is created.
backup_options
dict
This is a dict object containing configurable options related to backup file path. The value of this option is read only when C(backup) is set to I(yes), if C(backup) is set to I(no) this option will be silently ignored.
backup_options.dir_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 C(filename) or default filename as described in C(filename) options description. If the path value is not given in that case a I(backup) directory will be created in the current working directory and backup configuration will be copied in C(filename) within I(backup) directory.
backup_options.filename 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
bool
The C(commit) argument instructs the module to push the configuration to the device. This is mapped to module check mode.
commit_comment
str
The C(commit_comment) argument specifies a text string to be used when committing the configuration. If the C(commit) argument is set to False, this argument is silently ignored. This argument is only valid for the platforms that support commit operation with comment.
config
str
The config to be pushed to the network device. This argument is mutually exclusive with C(rollback) and either one of the option should be given as input. To ensure idempotency and correct diff the configuration lines should be similar to how they appear if present in the running configuration on device including the indentation.
defaults
bool
The I(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.
diff_ignore_lines
list / elements=str
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.
diff_match
str
Choices: line, strict, exact, none Instructs the module on the way to perform the matching of the set of commands against the current device config. If C(diff_match) is set to I(line), commands are matched line by line. If C(diff_match) is set to I(strict), command lines are matched with respect to position. If C(diff_match) is set to I(exact), command lines must be an equal match. Finally, if C(diff_match) is set to I(none), the module will not attempt to compare the source configuration with the running configuration on the remote device. Note that this parameter will be ignored if the platform has onbox diff support.
diff_replace
str
Choices: line, block, config Instructs the module on the way to perform the configuration on the device. If the C(diff_replace) argument is set to I(line) then the modified lines are pushed to the device in configuration mode. If the argument is set to I(block) then the entire command block is pushed to the device in configuration mode if any line is not correct. Note that this parameter will be ignored if the platform has onbox diff support.
multiline_delimiter
str
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.
replace
str
If the C(replace) argument is set to C(yes), it will replace the entire running-config of the device with the C(config) argument value. For devices that support replacing running configuration from file on device like NXOS/JUNOS, the C(replace) argument takes path to the file on the device that will be used for replacing the entire running-config. The value of C(config) option should be I(None) for such devices. Nexus 9K devices only support replace. Use I(net_put) or I(nxos_file_copy) in case of NXOS module to copy the flat file to remote device and then use set the fullpath to this argument.
rollback
int
The C(rollback) argument instructs the module to rollback the current configuration to the identifier specified in the argument. If the specified rollback identifier does not exist on the remote device, the module will fail. To rollback to the most recent commit, set the C(rollback) argument to 0. This option is mutually exclusive with C(config).

Notes

Note

  • The commands will be returned only for platforms that do not support onbox diff. The C(--diff) option with the playbook will return the difference in configuration for devices that has support for onbox diff
  • To 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 C(ansible_network_os) network platforms. See the :ref:Network Platform Options <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

Key Data Type Description Returned
backup_path str The full path to the backup file when backup is yes
commands list The set of commands that will be pushed to the remote device When I(supports_generated_diff=True) and I(supports_onbox_diff=False) in the platform's cliconf plugin
diff str The diff generated on the device when the commands were applied When I(supports_onbox_diff=True) in the platform's cliconf plugin

Authors

  • Trishna Guha (@trishnaguha)