25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
5.2KB

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