.. _vyos.vyos.vyos_config_module: ********************* vyos.vyos.vyos_config ********************* **Manage VyOS configuration on remote device** Version added: 1.0.0 .. contents:: :local: :depth: 1 Synopsis -------- - This module provides configuration file management of VyOS devices. It provides arguments for managing both the configuration file and state of the active configuration. All configuration statements are based on `set` and `delete` commands in the device configuration. Parameters ---------- .. raw:: html
Parameter Choices/Defaults Comments
allow_password_change
string
    Choices:
  • all
  • plaintext ←
  • encrypted
  • none
The allow_password_change argument specifies whether any configuration lines which would change a user's password should be filtered out. By default only plaintext password changes are allowed and any encrypted-password keys are filtered out. In order to allow all password updates, both plaintext and encrypted, set this argument to all.
Not applied when replace is set to config; the candidate is loaded as-is via VyOS's native load, which has no equivalent filtering mechanism.
backup
boolean
    Choices:
  • no ←
  • yes
The backup argument will backup the current devices active configuration to the Ansible control host prior to making any changes. If the backup_options value is not given, the backup file will be located in the 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
dictionary
This is a dict object containing configurable options related to backup file path. The value of this option is read only when backup is set to yes, if backup is set to no this option will be silently ignored.
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 or default filename as described in filename options description. If the path value is not given in that case a backup directory will be created in the current working directory and backup configuration will be copied in filename within backup directory.
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 <hostname>_config.<current-date>@<current-time>
comment
string
Default:
"configured by vyos_config"
Allows a commit description to be specified to be included when the configuration is committed. If the configuration is not changed or committed, this argument is ignored.
config
string
The config argument specifies the base configuration to use to compare against the desired configuration. If this value is not specified, the module will automatically retrieve the current active configuration from the remote device. The configuration lines in the option value should be similar to how it will appear if present in the running-configuration of the device including indentation to ensure idempotency and correct diff.
Ignored when replace is set to config.
confirm
string
    Choices:
  • automatic
  • manual
  • none
The confirm argument will tell vyos to revert to the previous configuration if not explicitly confirmed after applying the new config. When set to automatic this module will automatically confirm the configuration, if the current session remains working with the new config. When set to manual, this module does not issue the confirmation itself.
Defaults to automatic when match is set to enforce, since enforce can generate delete commands for configuration not mentioned in the candidate and a bad commit should self-revert rather than leave the device unreachable. Defaults to none for all other match values.
confirm_timeout
integer
Default:
10
Minutes to wait for confirmation before reverting the configuration. Does not apply when confirm is set to none .
lines
list / elements=string
The ordered set of commands that should be configured in the section. The commands must be the exact same commands as found in the device running-config as found in the device running-config to ensure idempotency and correct diff. Be sure to note the configuration command syntax as some commands are automatically modified by the device config parser.
Not supported when replace is set to config -- see replace below.
match
string
    Choices:
  • line ←
  • enforce
  • none
The match argument controls the method used to match against the current active configuration. By default, the desired config is matched against the active config and the deltas are loaded. If the match argument is set to none, the active configuration is ignored and the configuration is always loaded. If the match argument is set to enforce, the supplied lines or src are treated as the complete desired end-state of the configuration, rather than a set of deltas to apply. enforce enforces only the top-level configuration sections present in the supplied candidate as complete end-states; existing configuration within those sections but not mentioned in the candidate is removed, so enforce can generate delete commands for configuration the candidate does not mention. Top-level sections the candidate does not reference at all are left completely untouched. enforce is intended for candidates made up of set commands only; supplying delete lines alongside match=enforce is not supported and will raise an error.
Ignored when replace is set to config, since no line-level diff is computed in that mode.
replace
string
    Choices:
  • line ←
  • config
Controls how the module applies configuration to the device.
When set to line (default), the module computes a set/delete command diff and pushes only the changed lines -- this is the existing behavior, unchanged.
When set to config, the module uploads the full candidate configuration (src) to the device and issues VyOS's native load command in configuration mode, which replaces the running configuration wholesale with the candidate's exact contents. VyOS's own configuration engine performs the reconciliation, rather than the module computing per-line deltas. This mirrors the mechanism offered by cisco.iosxr.iosxr_config's replace=config.
replace=config requires src and does not accept lines -- there is no way to convert flat set/delete commands into the hierarchical form load requires without re-implementing VyOS's own config-tree builder.
As with src in the default line mode, the module does not validate the candidate's contents or format under replace=config -- supplying a well-formed, complete configuration is the caller's responsibility.
replace=config requires the device to accept file transfer (SCP) over the same network_cli SSH session used for configuration commands.
replace=config writes the candidate to a fixed path on the device (overwritten on each run, matching cisco.iosxr.iosxr_config's own replace=config precedent). Running replace=config concurrently against the same host is not supported.
Any configuration present on the device but omitted from the candidate will be removed, including management interfaces, SSH access, and login users if they are omitted. Always supply a complete configuration, never a partial one.
When capturing a candidate from the device's own output (for example via show configuration) rather than from a trusted, separately maintained source, be aware that VyOS may return masked placeholder values (for example a run of literal asterisks) in place of local users' encrypted-password/plaintext-password values when queried through automation, even though the identical command returns the real value when typed interactively at a terminal. Pushing a masked capture back through replace=config sends the literal placeholder as the new password value; VyOS's own commit-time validation is expected to reject an obviously malformed hash, but a masked value that happens to pass basic format validation could apply silently. Prefer sourcing replace=config candidates from a trusted, version-controlled artifact rather than a live automated capture whenever the configuration contains local password-based users.
Even under check_mode, the candidate is written to a temporary file on the device so that VyOS's own compare can produce an accurate preview diff. No commit occurs in check mode.
When combined with backup=yes, the value of changed reflects whether the backup file's content changed on the Ansible control node, not whether the device configuration changed -- this is existing behavior in the shared netcommon action plugin backing config-family modules across collections, not specific to replace=config.
save
boolean
    Choices:
  • no ←
  • yes
The save argument controls whether or not changes made to the active configuration are saved to disk. This is independent of committing the config. When set to True, the active configuration is saved.
src
path
The src argument specifies the path to the source config file to load. The source config file can either be in bracket format or set format. The source file can include Jinja2 template variables. The configuration lines in the source file should be similar to how it will appear if present in the running-configuration of the device including indentation to ensure idempotency and correct diff.
When replace is set to config, src is required and must contain a complete configuration in hierarchical/bracket format -- the same format produced by show configuration or found in /config/config.boot. Flat set/delete command format (as produced by show configuration commands) is not accepted in that mode; VyOS's native load command rejects it with a parse error.

Notes ----- .. note:: - Tested against VyOS 1.3.8, 1.4.2, the upcoming 1.5, and the rolling release of spring 2025. - This module works with connection ``ansible.netcommon.network_cli``. See `the VyOS OS Platform Options <../network/user_guide/platform_vyos.html>`_. - 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. - ``replace=config`` currently has no way to scope its effect to part of the configuration; it always operates against the entire device configuration. There is no ``path`` parameter to constrain it to a subtree. - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` Examples -------- .. code-block:: yaml - name: configure the remote device vyos.vyos.vyos_config: lines: - set system host-name {{ inventory_hostname }} - set service lldp - delete service dhcp-server - name: backup and load from file vyos.vyos.vyos_config: src: vyos.cfg backup: true - name: render a Jinja2 template onto the VyOS router vyos.vyos.vyos_config: match: enforce src: vyos_template.j2 - name: revert after ten minutes, if connection is lost vyos.vyos.vyos_config: src: vyos_template.j2 confirm: automatic - name: for idempotency, use full-form commands vyos.vyos.vyos_config: lines: # - set int eth eth2 description 'OUTSIDE' - set interface ethernet eth2 description 'OUTSIDE' - name: configurable backup path vyos.vyos.vyos_config: backup: true backup_options: filename: backup.cfg dir_path: /home/user - name: capture the complete hierarchical configuration for editing # replace=config requires the complete desired configuration in # hierarchical/bracket format -- never a partial one, and never flat # set-command format. `backup: true` alone won't work here: it captures # flat set-command output (via `show configuration commands`), which # replace=config's underlying `load` command rejects. Capture the # hierarchical form directly instead, edit it, then replace with the # edited whole, as shown here. vyos.vyos.vyos_command: commands: "show configuration" register: current_config - name: (edit current_config.stdout[0] as needed, save it locally, then) vyos.vyos.vyos_config: src: /home/user/edited_config.cfg replace: config Return Values ------------- Common return values are documented `here `_, the following are the fields unique to this module: .. raw:: html
Key Returned Description
backup_path
string
when backup is yes
The full path to the backup file

Sample:
/playbooks/ansible/backup/vyos_config.2016-07-16@22:28:34
commands
list
always
In replace=line mode (default), the list of set/delete commands sent to the device.
In replace=config mode, contains only the single load <path> command actually issued to the device -- not an itemized diff. See diff for the actual change content, sourced from VyOS's own compare output.

Sample:
['...', '...']
date
string
when backup is yes
The date extracted from the backup file name

Sample:
2016-07-16
filename
string
when backup is yes and filename is not specified in backup options
The name of the backup file

Sample:
vyos_config.2016-07-16@22:28:34
filtered
list
always
The list of configuration commands removed to avoid a load failure.
Not populated when replace is set to config.

Sample:
['...', '...']
shortname
string
when backup is yes and filename is not specified in backup options
The full path to the backup file excluding the timestamp

Sample:
/playbooks/ansible/backup/vyos_config
time
string
when backup is yes
The time extracted from the backup file name

Sample:
22:28:34


Status ------ Authors ~~~~~~~ - Nathaniel Case (@Qalthos)