Skip to content

Commit

Permalink
Ubuntu: Add static routes per interface instead of a separate single …
Browse files Browse the repository at this point in the history
…file (#1737)
  • Loading branch information
jbemmel authored Jan 4, 2025
1 parent 8efce2b commit 250cb8f
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions netsim/ansible/templates/initial/linux/ubuntu.j2
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ network:
SCRIPT
{% endif %}
# Interface addressing and bonds
# Interface addressing and bonds, including any static routes
{% for l in interfaces|default([]) if (l.ipv4 is defined or l.ipv6 is defined or l.dhcp is defined or l.type in ['lag','bond'])%}
cat <<SCRIPT > /etc/netplan/03-eth-{{ l.ifname }}.yaml
network:
Expand Down Expand Up @@ -174,28 +174,19 @@ network:
{% endif %}
- {{ l[af] }}
{% endfor %}
SCRIPT
{% endfor %}
{% if routing.static|default([]) %}
# Add IPv4 static routes
cat <<SCRIPT > /etc/netplan/04-routes.yaml
network:
version: 2
renderer: networkd
ethernets:
{% for intf in routing.static|map(attribute='nexthop.intf',default='')|unique if intf %}
{{ intf }}:
{% if routing.static|default([]) %}
{% for sr_entry in routing.static if sr_entry.nexthop.intf|default('') == l.ifname %}
{% if loop.first %}
routes:
{% for sr_entry in routing.static|default([]) if sr_entry.nexthop.intf|default('') == intf %}
{% endif %}
{% for sr_af in ['ipv4','ipv6'] if sr_af in sr_entry %}
- to: {{ sr_entry[sr_af] }}
via: {{ sr_entry.nexthop[sr_af] }}
{% endfor %}
{% endfor %}
{% endfor %}
{% endif %}
SCRIPT
{% endif %}
{% endfor %}
echo -n 'Starting netplan generate ' && date
netplan generate
Expand Down

0 comments on commit 250cb8f

Please sign in to comment.