Skip to content

Commit

Permalink
Ubuntu: Add static routes to interface file
Browse files Browse the repository at this point in the history
This allows for multiple different interface types
  • Loading branch information
jbemmel authored Jan 3, 2025
1 parent fe727fc commit 058876c
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 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,34 +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
{% for intf in routing.static|map(attribute='nexthop.intf',default='')|unique if intf %}
{% if loop.first %}
{% if 'bond' in intf %}
bonds:
{% else %}
ethernets:
{% endif %}
{% endif %}
{{ 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 058876c

Please sign in to comment.