您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

81 行
2.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. allow-hotplug {{dev}}
  7. {% if netifs[netif].type == "virt_ptp" %}
  8. # virt_pointopoint -> {{virt_host}} {{netifs[netif].virt_host_netif}}
  9. # ipv4
  10. {% for ip in netifs[netif] | json_query("ips[].ip") | ipv4("address") %}
  11. iface {{ dev }} inet static
  12. address {{ ip }}
  13. netmask 32
  14. {% if loop.index == 1 %}
  15. {% set gateway4 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv4("address") | first %}
  16. pointopoint {{ gateway4 }}
  17. gateway {{ gateway4 }}
  18. {% endif %}
  19. {% endfor %}
  20. # ipv6
  21. {% for ip in netifs[netif] | json_query("ips[].ip") | ipv6("address") %}
  22. iface {{ dev }} inet6 static
  23. address {{ ip }}
  24. netmask 128
  25. {% if loop.index == 1 %}
  26. gateway {{ hostvars[virt_host].netifs[netifs[netif].virt_host_netif].ll6 }}
  27. {% endif %}
  28. {% endfor %}
  29. {% else %}
  30. {% if netifs[netif].type == "bridge" %}
  31. # bridge
  32. iface {{ dev }} inet manual
  33. {% if netifs[netif].devices is defined %}
  34. bridge_ports {{ netifs[netif].devices | join(" ") }}
  35. {% else %}
  36. bridge_ports none
  37. {% endif %}
  38. {% endif %}
  39. {% for ip in netifs[netif].ips %}
  40. {% if ip.ip | ipv6 %}
  41. # ipv6 {{ip.ip}}
  42. iface {{ dev }} inet6 static
  43. address {{ ip.ip | ipv6('address') }}
  44. netmask {{ ip.ip | ipv6('prefix') }}
  45. {% endif %}
  46. {% if ip.ip | ipv4 %}
  47. # ipv4 {{ip.ip}}
  48. iface {{ dev }} inet static
  49. address {{ ip.ip | ipv4('address') }}
  50. network {{ ip.ip | ipv4('network') }}
  51. netmask {{ ip.ip | ipv4('prefix') }}
  52. broadcast {{ ip.ip | ipv4('broadcast') }}
  53. {% if loop.index == 1 and netifs[netif].routes is defined %}
  54. {% set default_route = netifs[netif].routes | json_query("[?to=='default']") | first %}
  55. gateway {{default_route.via}}
  56. {% endif %}
  57. {% endif %}
  58. {% endfor %}
  59. {% endif %}
  60. # dns resolvers
  61. iface {{ dev }} inet manual
  62. {% if netifs[netif].dns_resolvers is defined %}
  63. {% for nameserver in netifs[netif].dns_resolvers %}
  64. dns-nameserver {{ nameserver }}
  65. {% endfor %}
  66. {% endif %}
  67. {% if netifs[netif].dns_search is defined%}
  68. {% for search in netifs[netif].dns_search %}
  69. dns-search {{ search }}
  70. {% endfor %}
  71. {% endif %}