cli_config – Push text based configuration to network devices over network_cli

New in version 2.7.

Synopsis

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

Parameters

Parameter Choices/Defaults Comments
commit
boolean
    Choices:
  • no
  • yes
The commit argument instructs the module to push the configuration to the device. This is mapped to module check mode.
commit_comment
string
The commit_comment argument specifies a text string to be used when committing the configuration. If the 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
string
The config to be pushed to the network device. This argument is mutually exclusive with rollback and either one of the option should be given as input. The config should have indentation that the device uses.
defaults
boolean
    Choices:
  • no ←
  • yes
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.
diff_ignore_lines
-
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
-
    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 diff_match is set to line, commands are matched line by line. If diff_match is set to strict, command lines are matched with respect to position. If diff_match is set to exact, command lines must be an equal match. Finally, if diff_match is set to 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
-
    Choices:
  • line
  • block
  • config
Instructs the module on the way to perform the configuration on the device. If the diff_replace argument is set to line then the modified lines are pushed to the device in configuration mode. If the argument is set to 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
string
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
string
If the replace argument is set to yes, it will replace the entire running-config of the device with the config argument value. For NXOS devices, replace argument takes path to the file on the device that will be used for replacing the entire running-config. Nexus 9K devices only support replace. Use net_put or nxos_file_copy module to copy the flat file to remote device and then use set the fullpath to this argument.
rollback
-
The 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 rollback argument to 0. This option is mutually exclusive with config.

Examples

- name: configure device with config
  cli_config:
    config: "{{ lookup('template', 'basic/config.j2') }}"

- name: multiline config
  cli_config:
    config: |
      hostname foo
      feature nxapi

- name: configure device with config with defaults enabled
  cli_config:
    config: "{{ lookup('template', 'basic/config.j2') }}"
    defaults: yes

- name: Use diff_match
  cli_config:
    config: "{{ lookup('file', 'interface_config') }}"
    diff_match: none

- name: nxos replace config
  cli_config:
    replace: 'bootflash:nxoscfg'

- name: commit with comment
  cli_config:
    config: set system host-name foo
    commit_comment: this is a test

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
commands
list
always
The set of commands that will be pushed to the remote device

Sample:
['interface Loopback999', 'no shutdown']


Status

Red Hat Support

More information about Red Hat’s support of this module is available from this Red Hat Knowledge Base article.

Authors

  • Trishna Guha (@trishnaguha)

Hint

If you notice any issues in this documentation you can edit this document to improve it.