Convert Vyos set commands in to vyos config offline

Hi,

with these command is possible to convert a vyos config offline in to set commands.

:/opt/vyatta/share/vyatta-op/templates/show/configuration/commands$ cat node.def
help:  Show running configuration as set commands
run: cli-shell-api showCfg --show-active-only | vyos-config-to-commands

I need this exactly opposite

I have a list of set commands and this build me a vyos config file without loading in to a running vyos.

How I need this.

I have a lots of vyos installation as single instance that should be migrated in to a two node setup.

But to add high-availability , dhcp-server failover to insert in to a config.boot file is horrible.
with set commands would be very easy to handle

show configuration commands > save to file
add the failover commands to this config
remove duplicate entries sort -u is your friend :smiley:
change hostname etc

convert it to a config.boot config

deploy the new config to the vyos with the api as load config command over curl


curl -k --location --request POST 'https://vyos/config-file' \
--form data='{"op": "load", "file": "/config/test.config"}' \
--form key='MY-HTTPS-API-PLAINTEXT-KEY'

Why config file, the API can only use one single set command. Our config is ca. 400 bis 600 set commands that would be send to each vyos. I think that is not good to handle so many request.

Instead of converting your list of set commands to a config and using the API to load it, why not ssh to the instance and paste/source/exec/(curl … | sh) the set commands?

I want to save the config at first in my git repo

later all changes will be pushed from this git repo to the running vyos.

I don´t want to use ssh, it is more complicated in a jenkins pipline then a curl api request.

Why config file, the API can only use one single set command. Our config is ca. 400 bis 600 set commands that would be send to each vyos. I think that is not good to handle so many request.

See the following:
https://docs.vyos.io/en/equuleus/automation/vyos-api.html#configure

for the example:

The API pushes every request to a session and commit it. But some of VyOS components like DHCP and PPPoE Servers, IPSec, VXLAN, and other tunnels require full configuration for commit. The endpoint will process multiple commands when you pass them as a list to the data field.

curl -k --location --request POST 'https://vyos/configure' \
--form data='[{"op": "set","path":["interfaces","vxlan","vxlan1","remote","203.0.113.99"]}, {"op": "set","path":["interfaces","vxlan","vxlan1","vni","1"]}]' \
--form key='MY-HTTPS-API-PLAINTEXT-KEY'

So you could convert your set commands into a an array of { "op": "set", ... } and invoke like this.

This is a complex task because the file -> commands conversion can be done by just looking into the file syntax. But commands -> file requires a full tree of CLI nodes available, which is presented only inside binary deb packages or installed VyOS.

I understand your wish to load the full config file - it makes sense in many situations, and we have a simple trick that may help you with this. You will need to create an empty (or bare minimum) config, which is used as a base for all your commands. With it, you can do:

load /your/empty/config.file
set X
set Y
commit

This will be equal to a simple load /full/new/config.boot, but using set commands syntax instead. Of course, your set commands list should contain the full configuration, just like a config file.

i am not sure if I understand correct?

when I use a small config to load it and put all commands in to the console and say commit. Then I have on my template machine the prod config running. after commit the configuration is enable and running.

My suggestion is based on the fact that you do not need to convert a list of set commands into the configuration file. You can use this exact list of set commands with the same result as if you would load a configuration file.

So, to extract the configuration from the router you will need to do:

show configuration commands

instead of fetching /config/config.boot.

And to apply changes from your git repository, you will need to push an updated list of set commands, but with cleaning running configuration before this.

And then everything is done in one commit. We used this trick many times for configuration automation.

but the issue is I need an ssh session for this

How about managing your configuration with ansible? I have lots of vyos configurations too. Ansible will be more fit for you

1 Like