Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

97 рядки
4.9KB

  1. {{ ansible_managed | comment }}
  2. {% if netifs is defined %}
  3. {% for netif in netifs %}
  4. {% if netifs[netif].type == "ethernet" or netifs[netif].type == "virt" %}
  5. ### netif {{netif}}
  6. {# TODO list virt_pci_ids of all netifs and pick eth number by index of list #}
  7. {% set dev = 'eth'+(netifs[netif].virt_pci_id|string) %}
  8. auto {{dev}}
  9. {% if netifs[netif].type == "virt" and hostvars[virt_host].netifs[netifs[netif].virt_host_netif].type == "virt_pointopoint" %}
  10. # virt_pointopoint -> {{virt_host}} {{netifs[netif].virt_host_netif}}
  11. {% set ips_ipv4 = netifs[netif] | json_query("ips[].ip") | ipv4("address") %}
  12. {% set ips_ipv4_first = ips_ipv4 | first %}
  13. {% set ips_ipv4 = ips_ipv4 | difference(ips_ipv4_first) %}
  14. {% set virt_pointopoint_ips_ipv4 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv4("address") %}
  15. {% set virt_pointopoint_ips_ipv4_first = virt_pointopoint_ips_ipv4 | first %}
  16. {% set virt_pointopoint_ips_ipv4 = virt_pointopoint_ips_ipv4 | difference(virt_pointopoint_ips_ipv4_first) %}
  17. {% set ips_ipv6 = netifs[netif] | json_query("ips[].ip") | ipv6("address") %}
  18. {% set ips_ipv6_first = ips_ipv6 | first %}
  19. {% set ips_ipv6 = ips_ipv6 | difference(ips_ipv6_first) %}
  20. {% set virt_pointopoint_ips_ipv6 = hostvars[virt_host].netifs[netifs[netif].virt_host_netif] | json_query("ips[].ip") | ipv6("address") %}
  21. {% set virt_pointopoint_ips_ipv6_first = virt_pointopoint_ips_ipv6 | first %}
  22. {% set virt_pointopoint_ips_ipv6 = virt_pointopoint_ips_ipv6 | difference(virt_pointopoint_ips_ipv6_first) %}
  23. iface {{ dev }} inet manual
  24. post-up /sbin/ip link set dev {{ dev }} up
  25. pre-down /sbin/ip link set dev {{ dev }} down
  26. # ipv4
  27. post-up /sbin/ip -family inet address add {{ ips_ipv4_first }} peer {{ virt_pointopoint_ips_ipv4_first }} dev {{ dev }}
  28. pre-down /sbin/ip -family inet address del {{ ips_ipv4_first }} peer {{ virt_pointopoint_ips_ipv4_first }} dev {{ dev }}
  29. post-up /sbin/ip -family inet route add default dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }}
  30. pre-down /sbin/ip -family inet route del default dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }}
  31. {% for ptpip in virt_pointopoint_ips_ipv4 %}
  32. post-up /sbin/ip -family inet route add {{ ptpip }}/32 dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }}
  33. pre-down /sbin/ip -family inet route del {{ ptpip }}/32 dev {{ dev }} via {{ virt_pointopoint_ips_ipv4_first }}
  34. {% endfor %}
  35. {% for ip in ips_ipv4 %}
  36. post-up /sbin/ip -family inet address add {{ ip }}/32 dev {{ dev }}
  37. pre-down /sbin/ip -family inet address del {{ ip }}/32 dev {{ dev }}
  38. {% endfor %}
  39. # ipv6
  40. post-up /sbin/ip -family inet6 address add {{ ips_ipv6_first }}/128 dev {{ dev }}
  41. pre-down /sbin/ip -family inet6 address del {{ ips_ipv6_first }}/128 dev {{ dev }}
  42. post-up /sbin/ip -family inet6 route add {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }}
  43. post-up /sbin/ip -family inet6 route add default via {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }}
  44. pre-down /sbin/ip -family inet6 route del default via {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }}
  45. pre-down /sbin/ip -family inet6 route del {{ virt_pointopoint_ips_ipv6_first }} dev {{ dev }}
  46. {% for ptpip in virt_pointopoint_ips_ipv6 %}
  47. post-up /sbin/ip -family inet6 route add {{ ptpip }} dev {{ dev }} via {{ virt_pointopoint_ips_ipv6_first }}
  48. pre-down /sbin/ip -family inet6 route del {{ ptpip }} dev {{ dev }} via {{ virt_pointopoint_ips_ipv6_first }}
  49. {% endfor %}
  50. {% for ip in ips_ipv6 %}
  51. post-up /sbin/ip -family inet6 address add {{ ip }}/128 dev {{ dev }}
  52. pre-down /sbin/ip -family inet6 address del {{ ip }}/128 dev {{ dev }}
  53. {% endfor %}
  54. {% else %}
  55. {% for ip in netifs[netif].ips %}
  56. {% if ip.ip | ipv6 %}
  57. # ipv6 {{ip.ip}}
  58. iface {{ dev }} inet6 static
  59. address {{ ip.ip | ipv6('address') }}
  60. netmask {{ ip.ip | ipv6('netmask') }}
  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. {% endif %}
  68. {% if ip.ip | ipv4 %}
  69. # ipv4 {{ip.ip}}
  70. iface {{ dev }} inet static
  71. address {{ ip.ip | ipv4('address') }}
  72. network {{ ip.ip | ipv4('network') }}
  73. netmask {{ ip.ip | ipv4('prefix') }}
  74. broadcast {{ ip.ip | ipv4('broadcast') }}
  75. {% if loop.index == 1 and netifs[netif].routes is defined %}
  76. {% set default_route = netifs[netif].routes | json_query("[?to=='default']") | first %}
  77. gateway {{default_route.via}}
  78. {% endif %}
  79. {% if netifs[netif].dns_resolvers is defined and netifs[netif].dns_resolvers | ipv4 %}
  80. dns-nameservers {{ netifs[netif].dns_resolvers | ipv4 | join(" ") }}
  81. {% endif %}
  82. {% if netifs[netif].dns_search is defined %}
  83. dns-search {{ netifs[netif].dns_search | join(" ") }}
  84. {% endif %}
  85. {% endif %}
  86. {% endfor %}
  87. {% endif %}
  88. {% endif %}
  89. {% endfor %}
  90. {% endif %}