Liberalize static_route defenition

At the moment a very limited amount of options are supported for
static_routes defenition, which might be a limiting factor in some more
complex solutions.

It is proposed to let operators define `static_routes` with parameters
that are available in systemd-networkd [1] directly, which should
provide required flexbility and not require us additional maintenance
and regular updates of the code.

[1] https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html#%5BRoute%5D%20Section%20Options

Change-Id: I71f81cb497ae8eeb0fab2bc6f9f5eae120d10775
This commit is contained in:
Dmitriy Rabotyagov 2024-12-12 15:03:50 +01:00
parent dcc83c2448
commit 852739df6d
4 changed files with 32 additions and 8 deletions

View File

@ -64,8 +64,8 @@ Release notes for the project can be found at:
mtu: 9000
usedns: true
static_routes:
- gateway: "10.1.0.1"
cidr: "10.1.0.0/24"
- Gateway: "10.1.0.1"
Destination: "10.1.0.0/24"
config_overrides:
Network:
ConfigureWithoutCarrier: true

View File

@ -0,0 +1,15 @@
---
features:
- |
Keys for ``static_routes`` were liberalized and now can accept any
parameter supported by ``[Route]`` section of systemd-networkd.
upgrade:
- |
Following keys for ``static_routes`` list were renamed in order to
match with options available in systemd-networkd configuration files:
- ``cidr`` -> ``Destination``
- ``gateway`` -> ``Gateway``
While backwards compatability was kept, it's highly recommended to
use new keys as support for old key names will be removed in the future.

View File

@ -1,9 +1,18 @@
# {{ ansible_managed }}
{% for route in item['static_routes'] %}
[Route]
Destination={{ route['cidr'] }}
Gateway={{ route['gateway'] }}
Metric={{ 20 + loop.index }}
{% set route_keys = route.keys() %}
{% if 'cidr' in route_keys %}
{% set _ = route.update({'Destination': route.pop('cidr')}) %}
{% endif %}
{% if 'gateway' in route_keys %}
{% set _ = route.update({'Gateway': route.pop('gateway')}) %}
{% endif %}
[Route]
{% for key, value in route.items() %}
{{ key }}={{ value }}
{% endfor %}
{% if 'Metric' not in route_keys %}
Metric={{ 20 + loop.index }}
{% endif%}
{% endfor %}

View File

@ -74,7 +74,7 @@
mtu: 9000
usedns: true
static_routes:
- gateway: "10.1.0.1"
- Gateway: "10.1.0.1"
cidr: "10.1.0.0/24"
config_overrides:
Network: