diff --git a/README.md b/README.md index 297ae58..f499b8b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/releasenotes/notes/liberalize_static_routes_defenition-0625db80bcf2e2ed.yaml b/releasenotes/notes/liberalize_static_routes_defenition-0625db80bcf2e2ed.yaml new file mode 100644 index 0000000..58cc282 --- /dev/null +++ b/releasenotes/notes/liberalize_static_routes_defenition-0625db80bcf2e2ed.yaml @@ -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. diff --git a/templates/systemd-network-routes.j2 b/templates/systemd-network-routes.j2 index 81f9e06..ef58a63 100644 --- a/templates/systemd-network-routes.j2 +++ b/templates/systemd-network-routes.j2 @@ -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 %} diff --git a/tests/test.yml b/tests/test.yml index 1e85f56..dad8836 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -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: