From 762c276f61dd8fb599d9600df93c1a2992a8cf2e Mon Sep 17 00:00:00 2001 From: omnom62 <75066712+omnom62@users.noreply.github.com> Date: Wed, 16 Sep 2026 22:32:53 +1000 Subject: T6837: vyos_config replace (#493) * T6837: vyos_config replace core --- docs/vyos.vyos.vyos_config_module.rst | 62 ++++++++++++++++++++++++++++++++--- docs/vyos.vyos.vyos_user_module.rst | 4 +++ 2 files changed, 62 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/vyos.vyos.vyos_config_module.rst b/docs/vyos.vyos.vyos_config_module.rst index bf91bb0f..054ae208 100644 --- a/docs/vyos.vyos.vyos_config_module.rst +++ b/docs/vyos.vyos.vyos_config_module.rst @@ -52,6 +52,7 @@ Parameters
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.
@@ -85,7 +86,7 @@ Parameters -
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 true, if backup is set to false this option will be silently ignored.
+
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.
@@ -150,6 +151,7 @@ Parameters
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.
@@ -202,6 +204,7 @@ Parameters
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.
@@ -221,6 +224,36 @@ Parameters
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.
+
Ignored when replace is set to config, since no line-level diff is computed in that mode.
+ + + + +
+ replace + +
+ string +
+ + + + + +
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.
@@ -239,7 +272,7 @@ Parameters -
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.
+
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.
@@ -255,6 +288,7 @@ Parameters
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.
@@ -268,6 +302,7 @@ Notes - 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 ` @@ -311,6 +346,23 @@ Examples 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 @@ -353,7 +405,8 @@ Common return values are documented `here always -
The list of configuration commands sent to the device
+
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:
['...', '...']
@@ -404,7 +457,8 @@ Common return values are documented `here always -
The list of configuration commands removed to avoid a load failure
+
The list of configuration commands removed to avoid a load failure.
+
Not populated when replace is set to config.

Sample:
['...', '...']
diff --git a/docs/vyos.vyos.vyos_user_module.rst b/docs/vyos.vyos.vyos_user_module.rst index 42b8ccce..0f1ab9a2 100644 --- a/docs/vyos.vyos.vyos_user_module.rst +++ b/docs/vyos.vyos.vyos_user_module.rst @@ -188,6 +188,8 @@ Parameters
  • ecdsa-sha2-nistp384
  • ssh-ed25519
  • ecdsa-sha2-nistp521
  • +
  • sk-ecdsa-sha2-nistp256@openssh.com
  • +
  • sk-ssh-ed25519@openssh.com
  • @@ -365,6 +367,8 @@ Parameters
  • ecdsa-sha2-nistp384
  • ssh-ed25519
  • ecdsa-sha2-nistp521
  • +
  • sk-ecdsa-sha2-nistp256@openssh.com
  • +
  • sk-ssh-ed25519@openssh.com
  • -- cgit v1.2.3