Page MenuHomeVyOS Platform

Add replace configuration for module vyos_config
Closed, ResolvedPublicFEATURE REQUEST

Description

SUMMARY
We have many cases when creates automation deployments/uses cases, where we have the necessity to replace full configuration , I've seen in other modules that have this ability (https://docs.ansible.com/ansible/latest/collections/cisco/iosxr/iosxr_config_module.html#parameter-replace) it will be useful to get it for vyos_config module.

ADDITIONAL INFORMATION

example : https://docs.ansible.com/ansible/latest/collections/cisco/iosxr/iosxr_config_module.html#parameter-replace
- name: load a config from file/disk and replace the current config
  vyos.vyos.vyos_config:
    src: vyos.cfg
    replace: config
    backup: yes

Details

Version
-
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Feature (new functionality)

Event Timeline

syncer triaged this task as Normal priority.

I was looking for this too, and actually started to play with the code of the module to get this feature in a few weeks ago. I've submitted my changes as a draft PR on Github. I've been playing with managing my VyOS config from SCM for my home lab. It's important when I for example remove a firewall rule, it is also deleted in the running config, instead of being orphaned. It seems to work pretty well in my setup, but I am uncertain if nothing breaks in other workflows.

I was looking into this again today. As I mentioned in the pull request, there is an issue with the draft PR. What happens is that the current config is retrieved using the command show configuration commands instead of show configuration. The output does not contain any less specific config paths, as they would be useless in configuring a system. However, when determining what to delete, this information is essential.

For example:

running config:

firewall {
  ipv4 {
    name example {
      rule 100 {
        action drop
      }
      rule 200 {
        action accept
      }
    }
  }
}

candidate config:

firewall {
  ipv4 {
    name example {
      rule 100 {
        action drop
      }
    }
  }
}

retrieving the config results in:

set firewall ipv4 name example rule 100 action drop
set firewall ipv4 name example rule 200 action accept

With my code change the module is able to figure out to do the following:

delete firewall ipv4 name example rule 200 action accept

However this results in the invalid rule 200 config residue:

firewall {
  ipv4 {
    name example {
      rule 100 {
        action drop
      }
      rule 200 {
      }
    }
  }
}

I hope, that when we use show configuration instead, it's possible to determine the correct delete commands.

I tried looking into unit testing this and develop from there, but I'm not familiar with this testing tool chain. Does anyone have some pointer on how to run these unit tests locally?

Would be handy if a config replace would accept both show config and show config commands as inputs.

Are you able to elaborate, @Apachez?

Currently, the latest PR (vyos_config) grabs a configuration file (in the native boot format) and replaces the current configuration with load.
It also can produce diff.

What are the use cases for show config and show config commands, please?
Thanks!

The config in VyOS is stored in /config/config.boot as json-file.

The issue Im having with that is that sometimes (when doing a manual backup of config) I prefer the output of set-commands like show config commands.

However vyos-configd (or whoever it is that ingest /config/config.boot) clearly doesnt like the set-style and only accept json syntax.

Would be handy if vyos-configd (again or whatever process there is) would accept both json and set-syntax as input.

And by that also include any "config replace" to accept both json and set-style configs.

It seems we may need the both features: the one requested by this ticket, and the one that also allows for configuration in a form of flat, 'set/delete' commands?