|
- # interfaces(5) file used by ifup(8) and ifdown(8)
-
- {{ ansible_managed | comment }}
-
- auto lo
- iface lo inet loopback
-
- {% if network_interfaces is defined %}
- {% for netname,netif in network_interfaces.iteritems() %}
- ### {{ netname }} ###
- auto {{ netif.device }}
- {% if netif.hotplug | default(false) %}
- allow-hotplug {{ netif.device }}
- {% endif %}
-
- {% if netif.bridge is defined %}
- iface {{ netif.device }} inet manual
- bridge_ports {{ netif.bridge.ports | default(["none"]) | join(" ") }}
- bridge_stp {{ netif.bridge.stp | default(false) | ternary('on','off') }}
- {% endif %}
-
- {% for ipv4 in netif.ipv4 | default([]) %}
- iface {{ netif.device }} inet {{ ipv4.method }}
- {% if ipv4.method == "static" %}
- address {{ ipv4.address | ipv4('address') }}
- network {{ ipv4.address | ipv4('network') }}
- netmask {{ ipv4.address | ipv4('netmask') }}
- broadcast {{ ipv4.address | ipv4('broadcast') }}
- {% if ipv4.gateway is defined %}
- gateway {{ ipv4.gateway | ipv4('address') }}
- {% endif %}
- {% endif %}
- {% endfor %}
-
- {% for ipv6 in netif.ipv6 | default([]) %}
- iface {{ netif.device }} inet6 {{ ipv6.method }}
- {% if ipv6.method == "static" %}
- address {{ ipv6.address | ipv6('address') }}
- netmask {{ ipv6.address | ipv6('prefix') | default(128) }}
- {% if ipv6.gateway is defined %}
- {% if ( ( ipv6.address | ipv6('prefix') | int ) < 128 ) and ( ipv6.gateway | ipv6(ipv6.address) ) %}
- gateway {{ ipv6.gateway | ipv6('address') }}
- {% else %}
- post-up sleep 5; /sbin/ip -family inet6 route add {{ ipv6.gateway }} dev {{ netif.device }}
- post-up sleep 5; /sbin/ip -family inet6 route add default via {{ ipv6.gateway }}
- pre-down /sbin/ip -family inet6 route del default via {{ ipv6.gateway }}
- pre-down /sbin/ip -family inet6 route del {{ ipv6.gateway }} dev {{ netif.device }}
- {% endif %}
- {% endif %}
- {% endif %}
- {% endfor %}
-
- {% endfor %}
- {% endif %}
-
- {% if netifs is defined %}
- {% for netif in netifs %}
- {% if netifs[netif].type == "ethernet" or netifs[netif].type == "virt" %}
-
- ### netif {{netif}}
- {% set dev = netifs[netif].device | default( 'enx' + netifs[netif].mac | regex_replace(':') ) %}
- auto {{dev}}
-
- {% if netifs[netif].type == "virt" and hostvars[virt_host].netifs[netifs[netif].virt_host_netif].type == "virt_pointopoint" %}
-
- # virt_pointopoint -> {{virt_host}} {{netifs[netif].virt_host_netif}}
- {% set ips_ipv4 = netifs[netif] | json_query("ips[].ip") | ipv4("address") %}
- {% set ips_ipv4_first = ips_ipv4 | first %}
- {% set ips_ipv4 = ips_ipv4 | difference(ips_ipv4_first) %}
- {% set virt_pointopoint_ips_ipv4 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv4("address") %}
- {% set virt_pointopoint_ips_ipv4_first = virt_pointopoint_ips_ipv4 | first %}
- {% set virt_pointopoint_ips_ipv4 = virt_pointopoint_ips_ipv4 | difference(virt_pointopoint_ips_ipv4_first) %}
- {% set ips_ipv6 = netifs[netif] | json_query("ips[].ip") | ipv6("address") %}
- {% set ips_ipv6_first = ips_ipv6 | first %}
- {% set ips_ipv6 = ips_ipv6 | difference(ips_ipv6_first) %}
- {% set virt_pointopoint_ips_ipv6 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv6("address") %}
- {% set virt_pointopoint_ips_ipv6_first = virt_pointopoint_ips_ipv6 | first %}
- {% set virt_pointopoint_ips_ipv6 = virt_pointopoint_ips_ipv6 | difference(virt_pointopoint_ips_ipv6_first) %}
- iface {{ dev }} inet static
- address {{ ips_ipv4_first }}
- netmask 32
- pointopoint {{ virt_pointopoint_ips_ipv4_first }}
- gateway {{ virt_pointopoint_ips_ipv4_first }}
- {% for ptpip in virt_pointopoint_ips_ipv4 %}
- post-up /sbin/ip -family inet route add {{ ptpip }}/32 dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }}
- pre-down /sbin/ip -family inet route del {{ ptpip }}/32 dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }}
- {% endfor %}
- {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv4 %}
- dns-nameservers {{ netifs[netif].dns_resolvers | ipv4 | join(" ") }}
- {% endif %}
- {% if netifs[netif].dns_search is defined%}
- dns-search {{ netifs[netif].dns_search | join(" ") }}
- {% endif %}
- {% for ip in ips_ipv4 %}
- iface {{ dev }} inet static
- address {{ ip }}
- netmask 32
- {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv4 %}
- dns-nameservers {{ netifs[netif].dns_resolvers | ipv4 | join(" ") }}
- {% endif %}
- {% if netifs[netif].dns_search is defined %}
- dns-search {{ netifs[netif].dns_search | join(" ") }}
- {% endif %}
- {% endfor %}
- iface {{ dev }} inet6 static
- address {{ ips_ipv6_first }}
- netmask 128
- post-up /sbin/ip -family inet6 route add {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }}
- post-up /sbin/ip -family inet6 route add default via {{ virt_pointopoint_ips_ipv6_first }}
- pre-down /sbin/ip -family inet6 route del default via {{ virt_pointopoint_ips_ipv6_first }}
- pre-down /sbin/ip -family inet6 route del {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }}
- {% for ptpip in virt_pointopoint_ips_ipv6 %}
- post-up /sbin/ip -family inet6 route add {{ ptpip }} dev {{ dev }} via {{ virt_pointopoint_ips_ipv6_first }}
- pre-down /sbin/ip -family inet6 route del {{ ptpip }} dev {{ dev }} via {{ virt_pointopoint_ips_ipv6_first }}
- {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv6 %}
- dns-nameservers {{ netifs[netif].dns_resolvers | ipv6 | join(" ") }}
- {% endif %}
- {% if netifs[netif].dns_search is defined %}
- dns-search {{ netifs[netif].dns_search | join(" ") }}
- {% endif %}
- {% endfor %}
- {% for ip in ips_ipv6 %}
- iface {{ dev }} inet6 static
- address {{ ip }}
- netmask 128
- {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv6 %}
- dns-nameservers {{ netifs[netif].dns_resolvers | ipv6 | join(" ") }}
- {% endif %}
- {% if netifs[netif].dns_search is defined %}
- dns-search {{ netifs[netif].dns_search | join(" ") }}
- {% endif %}
- {% endfor %}
-
- {% else %}
-
- {% for ip in netifs[netif].ips %}
- {% if ip.ip | ipv6 %}
- # ipv6 {{ip.ip}}
- iface {{ dev }} inet6 static
- address {{ ip.ip | ipv6('address') }}
- netmask {{ ip.ip | ipv6('prefix') }}
- {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv6 %}
- dns-nameservers {{ netifs[netif].dns_resolvers | ipv6 | join(" ") }}
- {% endif %}
- {% if netifs[netif].dns_search is defined %}
- dns-search {{ netifs[netif].dns_search | join(" ") }}
- {% endif %}
- {% endif %}
- {% if ip.ip | ipv4 %}
- # ipv4 {{ip.ip}}
- iface {{ dev }} inet static
- address {{ ip.ip | ipv4('address') }}
- network {{ ip.ip | ipv4('network') }}
- netmask {{ ip.ip | ipv4('prefix') }}
- broadcast {{ ip.ip | ipv4('broadcast') }}
- {% if loop.index == 1 and netifs[netif].routes is defined %}
- {% set default_route = netifs[netif].routes | json_query("[?to=='default']") | first %}
- gateway {{default_route.via}}
- {% endif %}
- {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv4 %}
- dns-nameservers {{ netifs[netif].dns_resolvers | ipv4 | join(" ") }}
- {% endif %}
- {% if netifs[netif].dns_search is defined %}
- dns-search {{ netifs[netif].dns_search | join(" ") }}
- {% endif %}
- {% endif %}
- {% endfor %}
-
- {% endif %}
-
- {% endif %}
- {% endfor %}
- {% endif %}
-
- # Include files from /etc/network/interfaces.d:
- source-directory /etc/network/interfaces.d
|