Fix defenition of multiple static routes for network
Current logic was relying on iteration inside the template. However,
since config_template module was used to deliver network configuration
it was merging sections having same name together.
While this behaviour is correct one for config_template as all sections
must be unique from ConfigParser perspective and in order to apply
overrides properly, it was not suiting the way how routes should be
defined in networkd configuration.
To workaround the issue we place routes separately under <network>.d
directory, which should be supported by systemd [1]
[1] https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html
Closes-Bug: #2045819
Change-Id: I01aa44dcdc85e32d18dd52bcd4878a9017fb6ead
(cherry picked from commit 70442c5efb
)
This commit is contained in:
parent
97a27cf143
commit
a05e610cc5
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Multiple routes can be supplied to the systemd network and they will be
|
||||||
|
placed to a separate configuration file
|
||||||
|
`/etc/systemd/network/{{ filename }}.d/routes.conf`
|
||||||
|
|
||||||
|
Previously defining multiple routes will result in squashing them together
|
||||||
|
under same section name, while for them to work properly each descriped
|
||||||
|
route must be placed in it's own section.
|
|
@ -184,6 +184,24 @@
|
||||||
tags:
|
tags:
|
||||||
- systemd-networkd
|
- systemd-networkd
|
||||||
|
|
||||||
|
- name: Create systemd-networkd extra config folder
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "/etc/systemd/network/{{ item }}.network.d"
|
||||||
|
owner: "root"
|
||||||
|
group: "root"
|
||||||
|
mode: "0755"
|
||||||
|
state: directory
|
||||||
|
loop: "{{ _systemd_networks_named | selectattr('static_routes', 'defined') | map(attribute='filename') }}"
|
||||||
|
|
||||||
|
- name: Place systemd-networkd network routes
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: systemd-network-routes.j2
|
||||||
|
dest: "/etc/systemd/network/{{ item['filename'] }}.network.d/routes.conf"
|
||||||
|
owner: "root"
|
||||||
|
group: "root"
|
||||||
|
mode: "0644"
|
||||||
|
loop: "{{ _systemd_networks_named | selectattr('static_routes', 'defined') }}"
|
||||||
|
|
||||||
- name: Enable and start systemd-networkd
|
- name: Enable and start systemd-networkd
|
||||||
systemd:
|
systemd:
|
||||||
name: "systemd-networkd"
|
name: "systemd-networkd"
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
|
{% for route in item['static_routes'] %}
|
||||||
|
[Route]
|
||||||
|
Destination={{ route['cidr'] }}
|
||||||
|
Gateway={{ route['gateway'] }}
|
||||||
|
Metric={{ 20 + loop.index }}
|
||||||
|
|
||||||
|
{% endfor %}
|
|
@ -10,14 +10,6 @@ UseNTP=yes
|
||||||
RouteMetric=20
|
RouteMetric=20
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for route in item.1.static_routes | default([]) %}
|
|
||||||
[Route]
|
|
||||||
Destination={{ route['cidr'] }}
|
|
||||||
Gateway={{ route['gateway'] }}
|
|
||||||
Metric={{ 20 + loop.index }}
|
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{%- if item.1.address is not defined %}
|
{%- if item.1.address is not defined %}
|
||||||
{# Address is not defined #}
|
{# Address is not defined #}
|
||||||
{% set _addresses = [] %}
|
{% set _addresses = [] %}
|
||||||
|
|
Loading…
Reference in New Issue