選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

177 行
7.2KB

  1. # interfaces(5) file used by ifup(8) and ifdown(8)
  2. {{ ansible_managed | comment }}
  3. auto lo
  4. iface lo inet loopback
  5. {% if network_interfaces is defined %}
  6. {% for netname,netif in network_interfaces.iteritems() %}
  7. ### {{ netname }} ###
  8. auto {{ netif.device }}
  9. {% if netif.hotplug | default(false) %}
  10. allow-hotplug {{ netif.device }}
  11. {% endif %}
  12. {% if netif.bridge is defined %}
  13. iface {{ netif.device }} inet manual
  14. bridge_ports {{ netif.bridge.ports | default(["none"]) | join(" ") }}
  15. bridge_stp {{ netif.bridge.stp | default(false) | ternary('on','off') }}
  16. {% endif %}
  17. {% for ipv4 in netif.ipv4 | default([]) %}
  18. iface {{ netif.device }} inet {{ ipv4.method }}
  19. {% if ipv4.method == "static" %}
  20. address {{ ipv4.address | ipv4('address') }}
  21. network {{ ipv4.address | ipv4('network') }}
  22. netmask {{ ipv4.address | ipv4('netmask') }}
  23. broadcast {{ ipv4.address | ipv4('broadcast') }}
  24. {% if ipv4.gateway is defined %}
  25. gateway {{ ipv4.gateway | ipv4('address') }}
  26. {% endif %}
  27. {% endif %}
  28. {% endfor %}
  29. {% for ipv6 in netif.ipv6 | default([]) %}
  30. iface {{ netif.device }} inet6 {{ ipv6.method }}
  31. {% if ipv6.method == "static" %}
  32. address {{ ipv6.address | ipv6('address') }}
  33. netmask {{ ipv6.address | ipv6('prefix') | default(128) }}
  34. {% if ipv6.gateway is defined %}
  35. {% if ( ( ipv6.address | ipv6('prefix') | int ) < 128 ) and ( ipv6.gateway | ipv6(ipv6.address) ) %}
  36. gateway {{ ipv6.gateway | ipv6('address') }}
  37. {% else %}
  38. post-up sleep 5; /sbin/ip -family inet6 route add {{ ipv6.gateway }} dev {{ netif.device }}
  39. post-up sleep 5; /sbin/ip -family inet6 route add default via {{ ipv6.gateway }}
  40. pre-down /sbin/ip -family inet6 route del default via {{ ipv6.gateway }}
  41. pre-down /sbin/ip -family inet6 route del {{ ipv6.gateway }} dev {{ netif.device }}
  42. {% endif %}
  43. {% endif %}
  44. {% endif %}
  45. {% endfor %}
  46. {% endfor %}
  47. {% endif %}
  48. {% if netifs is defined %}
  49. {% for netif in netifs %}
  50. {% if netifs[netif].type == "ethernet" or netifs[netif].type == "virt" %}
  51. ### netif {{netif}}
  52. {% set dev = netifs[netif].device | default( 'enx' + netifs[netif].mac | regex_replace(':') ) %}
  53. auto {{dev}}
  54. {% if netifs[netif].type == "virt" and hostvars[virt_host].netifs[netifs[netif].virt_host_netif].type == "virt_pointopoint" %}
  55. # virt_pointopoint -> {{virt_host}} {{netifs[netif].virt_host_netif}}
  56. {% set ips_ipv4 = netifs[netif] | json_query("ips[].ip") | ipv4("address") %}
  57. {% set ips_ipv4_first = ips_ipv4 | first %}
  58. {% set ips_ipv4 = ips_ipv4 | difference(ips_ipv4_first) %}
  59. {% set virt_pointopoint_ips_ipv4 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv4("address") %}
  60. {% set virt_pointopoint_ips_ipv4_first = virt_pointopoint_ips_ipv4 | first %}
  61. {% set virt_pointopoint_ips_ipv4 = virt_pointopoint_ips_ipv4 | difference(virt_pointopoint_ips_ipv4_first) %}
  62. {% set ips_ipv6 = netifs[netif] | json_query("ips[].ip") | ipv6("address") %}
  63. {% set ips_ipv6_first = ips_ipv6 | first %}
  64. {% set ips_ipv6 = ips_ipv6 | difference(ips_ipv6_first) %}
  65. {% set virt_pointopoint_ips_ipv6 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv6("address") %}
  66. {% set virt_pointopoint_ips_ipv6_first = virt_pointopoint_ips_ipv6 | first %}
  67. {% set virt_pointopoint_ips_ipv6 = virt_pointopoint_ips_ipv6 | difference(virt_pointopoint_ips_ipv6_first) %}
  68. iface {{ dev }} inet static
  69. address {{ ips_ipv4_first }}
  70. netmask 32
  71. pointopoint {{ virt_pointopoint_ips_ipv4_first }}
  72. gateway {{ virt_pointopoint_ips_ipv4_first }}
  73. {% for ptpip in virt_pointopoint_ips_ipv4 %}
  74. post-up /sbin/ip -family inet route add {{ ptpip }}/32 dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }}
  75. pre-down /sbin/ip -family inet route del {{ ptpip }}/32 dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }}
  76. {% endfor %}
  77. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv4 %}
  78. dns-nameservers {{ netifs[netif].dns_resolvers | ipv4 | join(" ") }}
  79. {% endif %}
  80. {% if netifs[netif].dns_search is defined%}
  81. dns-search {{ netifs[netif].dns_search | join(" ") }}
  82. {% endif %}
  83. {% for ip in ips_ipv4 %}
  84. iface {{ dev }} inet static
  85. address {{ ip }}
  86. netmask 32
  87. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv4 %}
  88. dns-nameservers {{ netifs[netif].dns_resolvers | ipv4 | join(" ") }}
  89. {% endif %}
  90. {% if netifs[netif].dns_search is defined %}
  91. dns-search {{ netifs[netif].dns_search | join(" ") }}
  92. {% endif %}
  93. {% endfor %}
  94. iface {{ dev }} inet6 static
  95. address {{ ips_ipv6_first }}
  96. netmask 128
  97. post-up /sbin/ip -family inet6 route add {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }}
  98. post-up /sbin/ip -family inet6 route add default via {{ virt_pointopoint_ips_ipv6_first }}
  99. pre-down /sbin/ip -family inet6 route del default via {{ virt_pointopoint_ips_ipv6_first }}
  100. pre-down /sbin/ip -family inet6 route del {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }}
  101. {% for ptpip in virt_pointopoint_ips_ipv6 %}
  102. post-up /sbin/ip -family inet6 route add {{ ptpip }} dev {{ dev }} via {{ virt_pointopoint_ips_ipv6_first }}
  103. pre-down /sbin/ip -family inet6 route del {{ ptpip }} dev {{ dev }} via {{ virt_pointopoint_ips_ipv6_first }}
  104. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv6 %}
  105. dns-nameservers {{ netifs[netif].dns_resolvers | ipv6 | join(" ") }}
  106. {% endif %}
  107. {% if netifs[netif].dns_search is defined %}
  108. dns-search {{ netifs[netif].dns_search | join(" ") }}
  109. {% endif %}
  110. {% endfor %}
  111. {% for ip in ips_ipv6 %}
  112. iface {{ dev }} inet6 static
  113. address {{ ip }}
  114. netmask 128
  115. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv6 %}
  116. dns-nameservers {{ netifs[netif].dns_resolvers | ipv6 | join(" ") }}
  117. {% endif %}
  118. {% if netifs[netif].dns_search is defined %}
  119. dns-search {{ netifs[netif].dns_search | join(" ") }}
  120. {% endif %}
  121. {% endfor %}
  122. {% else %}
  123. {% for ip in netifs[netif].ips %}
  124. {% if ip.ip | ipv6 %}
  125. # ipv6 {{ip.ip}}
  126. iface {{ dev }} inet6 static
  127. address {{ ip.ip | ipv6('address') }}
  128. netmask {{ ip.ip | ipv6('prefix') }}
  129. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv6 %}
  130. dns-nameservers {{ netifs[netif].dns_resolvers | ipv6 | join(" ") }}
  131. {% endif %}
  132. {% if netifs[netif].dns_search is defined %}
  133. dns-search {{ netifs[netif].dns_search | join(" ") }}
  134. {% endif %}
  135. {% endif %}
  136. {% if ip.ip | ipv4 %}
  137. # ipv4 {{ip.ip}}
  138. iface {{ dev }} inet static
  139. address {{ ip.ip | ipv4('address') }}
  140. network {{ ip.ip | ipv4('network') }}
  141. netmask {{ ip.ip | ipv4('prefix') }}
  142. broadcast {{ ip.ip | ipv4('broadcast') }}
  143. {% if loop.index == 1 and netifs[netif].routes is defined %}
  144. {% set default_route = netifs[netif].routes | json_query("[?to=='default']") | first %}
  145. gateway {{default_route.via}}
  146. {% endif %}
  147. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv4 %}
  148. dns-nameservers {{ netifs[netif].dns_resolvers | ipv4 | join(" ") }}
  149. {% endif %}
  150. {% if netifs[netif].dns_search is defined %}
  151. dns-search {{ netifs[netif].dns_search | join(" ") }}
  152. {% endif %}
  153. {% endif %}
  154. {% endfor %}
  155. {% endif %}
  156. {% endif %}
  157. {% endfor %}
  158. {% endif %}
  159. # Include files from /etc/network/interfaces.d:
  160. source-directory /etc/network/interfaces.d