No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

129 líneas
5.5KB

  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 netifs is defined %}
  6. {% for netif in netifs %}
  7. {% if netifs[netif].type == "ethernet" or netifs[netif].type == "virt" %}
  8. ### netif {{netif}}
  9. {% set dev = netifs[netif].device | default( 'enx' + netifs[netif].mac | regex_replace(':') ) %}
  10. auto {{dev}}
  11. {% if netifs[netif].type == "virt" and hostvars[virt_host].netifs[netifs[netif].virt_host_netif].type == "virt_pointopoint" %}
  12. # virt_pointopoint -> {{virt_host}} {{netifs[netif].virt_host_netif}}
  13. {% set ips_ipv4 = netifs[netif] | json_query("ips[].ip") | ipv4("address") %}
  14. {% set ips_ipv4_first = ips_ipv4 | first %}
  15. {% set ips_ipv4 = ips_ipv4 | difference(ips_ipv4_first) %}
  16. {% set virt_pointopoint_ips_ipv4 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv4("address") %}
  17. {% set virt_pointopoint_ips_ipv4_first = virt_pointopoint_ips_ipv4 | first %}
  18. {% set virt_pointopoint_ips_ipv4 = virt_pointopoint_ips_ipv4 | difference(virt_pointopoint_ips_ipv4_first) %}
  19. {% set ips_ipv6 = netifs[netif] | json_query("ips[].ip") | ipv6("address") %}
  20. {% set ips_ipv6_first = ips_ipv6 | first %}
  21. {% set ips_ipv6 = ips_ipv6 | difference(ips_ipv6_first) %}
  22. {% set virt_pointopoint_ips_ipv6 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv6("address") %}
  23. {% set virt_pointopoint_ips_ipv6_first = virt_pointopoint_ips_ipv6 | first %}
  24. {% set virt_pointopoint_ips_ipv6 = virt_pointopoint_ips_ipv6 | difference(virt_pointopoint_ips_ipv6_first) %}
  25. iface {{ dev }} inet static
  26. address {{ ips_ipv4_first }}
  27. netmask 32
  28. pointopoint {{ virt_pointopoint_ips_ipv4_first }}
  29. gateway {{ virt_pointopoint_ips_ipv4_first }}
  30. {% for ptpip in virt_pointopoint_ips_ipv4 %}
  31. post-up /sbin/ip -family inet route add {{ ptpip }}/32 dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }}
  32. pre-down /sbin/ip -family inet route del {{ ptpip }}/32 dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }}
  33. {% endfor %}
  34. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv4 %}
  35. dns-nameservers {{ netifs[netif].dns_resolvers | ipv4 | join(" ") }}
  36. {% endif %}
  37. {% if netifs[netif].dns_search is defined%}
  38. dns-search {{ netifs[netif].dns_search | join(" ") }}
  39. {% endif %}
  40. {% for ip in ips_ipv4 %}
  41. iface {{ dev }} inet static
  42. address {{ ip }}
  43. netmask 32
  44. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv4 %}
  45. dns-nameservers {{ netifs[netif].dns_resolvers | ipv4 | join(" ") }}
  46. {% endif %}
  47. {% if netifs[netif].dns_search is defined %}
  48. dns-search {{ netifs[netif].dns_search | join(" ") }}
  49. {% endif %}
  50. {% endfor %}
  51. iface {{ dev }} inet6 static
  52. address {{ ips_ipv6_first }}
  53. netmask 128
  54. post-up /sbin/ip -family inet6 route add {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }}
  55. post-up /sbin/ip -family inet6 route add default via {{ virt_pointopoint_ips_ipv6_first }}
  56. pre-down /sbin/ip -family inet6 route del default via {{ virt_pointopoint_ips_ipv6_first }}
  57. pre-down /sbin/ip -family inet6 route del {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }}
  58. {% for ptpip in virt_pointopoint_ips_ipv6 %}
  59. post-up /sbin/ip -family inet6 route add {{ ptpip }} dev {{ dev }} via {{ virt_pointopoint_ips_ipv6_first }}
  60. pre-down /sbin/ip -family inet6 route del {{ ptpip }} dev {{ dev }} via {{ virt_pointopoint_ips_ipv6_first }}
  61. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv6 %}
  62. dns-nameservers {{ netifs[netif].dns_resolvers | ipv6 | join(" ") }}
  63. {% endif %}
  64. {% if netifs[netif].dns_search is defined %}
  65. dns-search {{ netifs[netif].dns_search | join(" ") }}
  66. {% endif %}
  67. {% endfor %}
  68. {% for ip in ips_ipv6 %}
  69. iface {{ dev }} inet6 static
  70. address {{ ip }}
  71. netmask 128
  72. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv6 %}
  73. dns-nameservers {{ netifs[netif].dns_resolvers | ipv6 | join(" ") }}
  74. {% endif %}
  75. {% if netifs[netif].dns_search is defined %}
  76. dns-search {{ netifs[netif].dns_search | join(" ") }}
  77. {% endif %}
  78. {% endfor %}
  79. {% else %}
  80. {% for ip in netifs[netif].ips %}
  81. {% if ip.ip | ipv6 %}
  82. # ipv6 {{ip.ip}}
  83. iface {{ dev }} inet6 static
  84. address {{ ip.ip | ipv6('address') }}
  85. netmask {{ ip.ip | ipv6('prefix') }}
  86. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv6 %}
  87. dns-nameservers {{ netifs[netif].dns_resolvers | ipv6 | join(" ") }}
  88. {% endif %}
  89. {% if netifs[netif].dns_search is defined %}
  90. dns-search {{ netifs[netif].dns_search | join(" ") }}
  91. {% endif %}
  92. {% endif %}
  93. {% if ip.ip | ipv4 %}
  94. # ipv4 {{ip.ip}}
  95. iface {{ dev }} inet static
  96. address {{ ip.ip | ipv4('address') }}
  97. network {{ ip.ip | ipv4('network') }}
  98. netmask {{ ip.ip | ipv4('prefix') }}
  99. broadcast {{ ip.ip | ipv4('broadcast') }}
  100. {% if loop.index == 1 and netifs[netif].routes is defined %}
  101. {% set default_route = netifs[netif].routes | json_query("[?to=='default']") | first %}
  102. gateway {{default_route.via}}
  103. {% endif %}
  104. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv4 %}
  105. dns-nameservers {{ netifs[netif].dns_resolvers | ipv4 | join(" ") }}
  106. {% endif %}
  107. {% if netifs[netif].dns_search is defined %}
  108. dns-search {{ netifs[netif].dns_search | join(" ") }}
  109. {% endif %}
  110. {% endif %}
  111. {% endfor %}
  112. {% endif %}
  113. {% endif %}
  114. {% endfor %}
  115. {% endif %}
  116. # Include files from /etc/network/interfaces.d:
  117. source-directory /etc/network/interfaces.d