Skip to content

Commit 4247998

Browse files
authored
VyOS: Implement configuration templates using only 'set' commands (#2572)
VyOS configuration templates are vbash scripts that include a lot of setup and cleanup code. The same code is replicated in every template. That is not good by itself, but it doesn't allow the users to use simple custom config templates with just the 'set' commands. This change implements configuration deployment similar to what we're doing for FRR: if the configuration code includes 'vbash', it's executed as-is, otherwise it's wrapped in a standard vbash script. Also changed: * The 'are we ready' check has been moved from the 'deploy config' task list to 'readyness check' task list * The 'fetch config' task list fetches device configuration as 'set' commands, allowing it to be used directly as a custom config template. That should allow 'netlab up --reload' to work with VyOS. * BGP and IS-IS templates have been cleaned up as a proof-of-concept
1 parent f3053c1 commit 4247998

File tree

6 files changed

+32
-55
lines changed

6 files changed

+32
-55
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% if 'vbash' in script_content %}
2+
{{ script_content }}
3+
{% else %}
4+
#!/bin/vbash
5+
source /opt/vyatta/etc/functions/script-template
6+
7+
if [ "$(id -g -n)" != 'vyattacfg' ] ; then
8+
exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@"
9+
fi
10+
11+
# Configuration items start here
12+
configure
13+
14+
{{ script_content }}
15+
16+
commit
17+
save
18+
exit
19+
{% endif %}

netsim/ansible/tasks/deploy-config/vyos.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
- block:
2-
- wait_for_connection:
3-
timeout: 120
4-
sleep: 3
5-
- wait_for:
6-
timeout: 120
7-
path: /tmp/vyos-config-status
8-
when: |
9-
node_provider == 'clab' and vyos_booted is not defined
10-
11-
- set_fact:
12-
vyos_booted: 1
13-
141
- set_fact:
2+
script_content: "{{ lookup('template',config_template) }}"
153
destination_script: "/tmp/config-{{ netsim_action|replace('/', '_') }}.sh"
164

175
- template:
18-
src: "{{ config_template }}"
6+
src: vyos-script.j2
197
dest: "{{ destination_script }}"
208

219
- name: "execute config-{{ netsim_action }}.sh to deploy {{ netsim_action }} config from {{ config_template }}"
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#
2-
# Fetch VyOS boot configuration files
2+
# Fetch VyOS configuration commands
33
#
4-
- fetch:
5-
src: "{{ item }}"
6-
dest: "{{ config_dir }}/{{ inventory_hostname }}/"
7-
flat: yes
8-
become: True
9-
loop:
10-
- /config/config.boot
4+
- name: Collect VyOS configuration
5+
shell: /bin/vbash -cil 'show configuration commands'
6+
register: config
7+
- set_fact: ansible_net_config={{ config.stdout }}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- wait_for_connection:
2+
timeout: 120
3+
sleep: 3
4+
- wait_for:
5+
timeout: 120
6+
path: /tmp/vyos-config-status

netsim/ansible/templates/bgp/vyos.j2

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
#!/bin/vbash
2-
source /opt/vyatta/etc/functions/script-template
3-
4-
if [ "$(id -g -n)" != 'vyattacfg' ] ; then
5-
exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@"
6-
fi
7-
8-
# Configuration items start here
91
{% import "vyos.macro.j2" as bgpcfg %}
102

11-
configure
12-
133
set protocols bgp system-as {{ bgp.as }}
144

155
{% if bgp.router_id|ipv4 %}
@@ -64,10 +54,3 @@ set protocols bgp address-family {{ af }}-unicast redistribute {{ s_proto }}{%
6454
{% for pfx in bgp.originate|default([]) %}
6555
set protocols static route {{ pfx|ipaddr('0') }} blackhole
6656
{% endfor %}
67-
68-
# Commit, save and exit from subshell
69-
70-
commit
71-
save
72-
exit
73-

netsim/ansible/templates/isis/vyos.j2

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
#!/bin/vbash
2-
source /opt/vyatta/etc/functions/script-template
3-
4-
if [ "$(id -g -n)" != 'vyattacfg' ] ; then
5-
exec sg vyattacfg -c "/bin/vbash $(readlink -f $0) $@"
6-
fi
7-
8-
# Configuration items start here
9-
configure
10-
111
set protocols isis level {{ isis.type }}
12-
132
set protocols isis dynamic-hostname
143
set protocols isis lsp-gen-interval 1
154
set protocols isis spf-interval 1
@@ -41,8 +30,3 @@ set protocols isis interface {{ l.ifname }} bfd profile netsim
4130
{% endif %}
4231

4332
{% endfor %}
44-
# Commit, save and exit from subshell
45-
46-
commit
47-
save
48-
exit

0 commit comments

Comments
 (0)