Skip to content

Commit 270f4c1

Browse files
committed
[radvd] radvd config snippet pretty rendering
Improve the template so that it renders radvd config snippets nicely with indentation and newlines. Also add a test in molecule to validate rendering. Signed-off-by: Harald Jensås <[email protected]>
1 parent ffa7b99 commit 270f4c1

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

roles/radvd/molecule/default/converge.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@
108108
- "'AdvAutonomous on' in _config"
109109
- "'AdvRouterAddr on' in _config"
110110

111+
- name: Verify testnet1 configuration formatting is correct
112+
vars:
113+
_config_lines: "{{ (_testnet1_conf.content | b64decode).split('\n') }}"
114+
ansible.builtin.assert:
115+
that:
116+
# Check directives are on separate lines (not squished together)
117+
- _config_lines | select('match', '.*;.*AdvManagedFlag') | list | length == 0
118+
- _config_lines | select('match', '.*;.*AdvOtherConfigFlag') | list | length == 0
119+
- _config_lines | select('match', '.*;.*AdvLinkMTU') | list | length == 0
120+
# Check specific lines have proper formatting (one directive per line)
121+
- _config_lines | select('match', '^ AdvManagedFlag on;$') | list | length == 1
122+
- _config_lines | select('match', '^ AdvOtherConfigFlag on;$') | list | length == 1
123+
- _config_lines | select('match', '^ AdvLinkMTU 1500;$') | list | length == 1
124+
msg: "Configuration formatting is incorrect - directives may be squished together on the same line"
125+
111126
- name: Verify testnet2 configuration has RDNSS
112127
become: true
113128
ansible.builtin.slurp:

roles/radvd/templates/network.conf.j2

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,60 @@
44
interface {{ cifmw_radvd_network.name }}
55
{
66
AdvSendAdvert {{ (cifmw_radvd_network.adv_send_advert | default(true)) | ternary('on', 'off') }};
7-
{%- if cifmw_radvd_network.adv_managed_flag is defined %}
7+
{% if cifmw_radvd_network.adv_managed_flag is defined %}
88
AdvManagedFlag {{ cifmw_radvd_network.adv_managed_flag | ternary('on', 'off') }};
9-
{%- endif %}
10-
{%- if cifmw_radvd_network.adv_other_config_flag is defined %}
9+
{% endif %}
10+
{% if cifmw_radvd_network.adv_other_config_flag is defined %}
1111
AdvOtherConfigFlag {{ cifmw_radvd_network.adv_other_config_flag | ternary('on', 'off') }};
12-
{%- endif %}
13-
{%- if cifmw_radvd_network.adv_ra_solicited_unicast is defined %}
12+
{% endif %}
13+
{% if cifmw_radvd_network.adv_ra_solicited_unicast is defined %}
1414
AdvRASolicitedUnicast {{ cifmw_radvd_network.adv_ra_solicited_unicast | ternary('on', 'off') }};
15-
{%- endif %}
16-
{%- if cifmw_radvd_network.adv_link_mtu is defined %}
15+
{% endif %}
16+
{% if cifmw_radvd_network.adv_link_mtu is defined %}
1717
AdvLinkMTU {{ cifmw_radvd_network.adv_link_mtu }};
18-
{%- endif %}
19-
{%- if cifmw_radvd_network.min_rtr_adv_interval is defined %}
18+
{% endif %}
19+
{% if cifmw_radvd_network.min_rtr_adv_interval is defined %}
2020
MinRtrAdvInterval {{ cifmw_radvd_network.min_rtr_adv_interval }};
21-
{%- endif %}
22-
{%- if cifmw_radvd_network.max_rtr_adv_interval is defined %}
21+
{% endif %}
22+
{% if cifmw_radvd_network.max_rtr_adv_interval is defined %}
2323
MaxRtrAdvInterval {{ cifmw_radvd_network.max_rtr_adv_interval }};
24-
{%- endif %}
25-
{%- for prefix in cifmw_radvd_network.prefixes | default([]) %}
24+
{% endif %}
25+
{% for prefix in cifmw_radvd_network.prefixes | default([]) %}
2626
prefix {{ prefix.network }}
2727
{
2828
AdvOnLink {{ (prefix.adv_on_link | default(true)) | ternary('on', 'off') }};
2929
AdvAutonomous {{ (prefix.adv_autonomous | default(true)) | ternary('on', 'off') }};
30-
{%- if prefix.adv_router_addr is defined %}
30+
{% if prefix.adv_router_addr is defined %}
3131
AdvRouterAddr {{ prefix.adv_router_addr | ternary('on', 'off') }};
32-
{%- endif %}
33-
{%- if prefix.adv_valid_lifetime is defined %}
32+
{% endif %}
33+
{% if prefix.adv_valid_lifetime is defined %}
3434
AdvValidLifetime {{ prefix.adv_valid_lifetime }};
35-
{%- endif %}
36-
{%- if prefix.adv_preferred_lifetime is defined %}
35+
{% endif %}
36+
{% if prefix.adv_preferred_lifetime is defined %}
3737
AdvPreferredLifetime {{ prefix.adv_preferred_lifetime }};
38-
{%- endif %}
38+
{% endif %}
3939
};
4040

41-
{%- endfor %}
42-
{%- for route in cifmw_radvd_network.routes | default([]) %}
41+
{% endfor %}
42+
{% for route in cifmw_radvd_network.routes | default([]) %}
4343
route {{ route.network }}
4444
{
45-
{%- if route.adv_route_preference is defined %}
45+
{% if route.adv_route_preference is defined %}
4646
AdvRoutePreference {{ route.adv_route_preference }};
47-
{%- endif %}
48-
{%- if route.adv_route_lifetime is defined %}
47+
{% endif %}
48+
{% if route.adv_route_lifetime is defined %}
4949
AdvRouteLifetime {{ route.adv_route_lifetime }};
50-
{%- endif %}
50+
{% endif %}
5151
};
5252

53-
{%- endfor %}
54-
{%- for rdnss in cifmw_radvd_network.rdnss | default([]) %}
53+
{% endfor %}
54+
{% for rdnss in cifmw_radvd_network.rdnss | default([]) %}
5555
RDNSS {{ rdnss.servers | join(' ') }}
5656
{
57-
{%- if rdnss.adv_rdnss_lifetime is defined %}
57+
{% if rdnss.adv_rdnss_lifetime is defined %}
5858
AdvRDNSSLifetime {{ rdnss.adv_rdnss_lifetime }};
59-
{%- endif %}
59+
{% endif %}
6060
};
6161

62-
{%- endfor %}
62+
{% endfor %}
6363
};

0 commit comments

Comments
 (0)