batman.j2 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # This file is managed by ansible, don't make changes here - they will be overwritten.
  2. {% set indexer = [0] -%}
  3. {% for domaene in domaenen|dictsort %}
  4. {% set group = "gateways" -%}
  5. {% if domaene[0] == "00" -%}
  6. {% set group = "domaene-test" -%}
  7. {% endif -%}
  8. {% if "domaene-"+domaene[0] in groups -%}
  9. {% set group = "domaene-"+domaene[0] -%}
  10. {% endif -%}
  11. # BEGIN: Domäne-{{domaene[0]}}
  12. {% if indexer.append(indexer.pop() + 1) %}{% endif %}{# increment indexer by 1 #}
  13. # BATMAN Interface für Domäne-{{domaene[0]}}
  14. auto bat{{domaene[0]}}
  15. iface bat{{domaene[0]}} inet6 static
  16. address fe80::dcad:beff:feef:{{ '%02x' % indexer[0] }}{{'%02d' % server_id}}
  17. netmask 64
  18. pre-up modprobe batman-adv
  19. pre-up ip link add bat{{domaene[0]}} type batadv
  20. post-up ip link set address de:ad:be:ef:{{ '%02x' % indexer[0] }}:{{server_id}} dev bat{{domaene[0]}}
  21. post-up ip link set dev bat{{domaene[0]}} up
  22. post-up batctl -m bat{{domaene[0]}} it 10000
  23. {% for host in groups[group] %}
  24. {% if group == "gateways" %}
  25. {% if domaene[0] in hostvars[host].domaenenliste %}
  26. post-up batctl -m bat{{domaene[0]}} if add t{{domaene[0]}}-{{ host }} ||:
  27. {% endif %}
  28. {% else %}
  29. post-up batctl -m bat{{domaene[0]}} if add tap-{{ host }} ||:
  30. {% endif %}
  31. {% endfor %}
  32. post-up ip -6 addr add {{domaene[1].ffv6_network | ipaddr(server_id) | ipaddr('address')}}/64 dev bat{{domaene[0]}}
  33. post-up pgrep -a -x -f "alfred -i bat{{domaene[0]}}.*" || alfred -i bat{{domaene[0]}} -b bat{{domaene[0]}} -u /run/alfred.{{domaene[0]}}.sock -m >/dev/null&
  34. post-up pgrep -a -x -f "batadv-vis -i bat{{domaene[0]}}.*" || batadv-vis -i bat{{domaene[0]}} -u /run/batadvvis.{{domaene[0]}}.sock -s >/dev/null 2>&1&
  35. pre-down pkill -x -f "alfred -i bat{{domaene[0]}}.*" ||:
  36. pre-down pkill -x -f "batadv-vis -i bat{{domaene[0]}}.*" ||:
  37. iface bat{{domaene[0]}} inet static
  38. address {{domaene[1].ffv4_network | ipaddr(server_id) | ipaddr('address') }}
  39. netmask {{domaene[1].ffv4_network | ipaddr('netmask')}}
  40. post-down ip link del bat{{domaene[0]}}
  41. # Tunnel-Interfaces für Domäne-{{domaene[0]}}
  42. {% for host in groups[group] %}
  43. {% if group == "gateways" %}
  44. {% if domaene[0] in hostvars[host].domaenenliste %}
  45. {% if indexer.append(indexer.pop() + 1) %}{% endif %}{# increment indexer by 1 #}
  46. auto t{{domaene[0]}}-{{ host }}
  47. iface t{{domaene[0]}}-{{ host }} inet manual
  48. pre-up ip link add $IFACE type gretap local {{ansible_default_ipv4.address}} remote {{hostvars[host].ansible_ssh_host}} dev eth0 key {{domaene[0]|int}}
  49. pre-up ip link set dev $IFACE address de:ad:be:ef:{{ '%02x' % indexer[0] }}:{{server_id}}
  50. pre-up ip link set $IFACE up
  51. post-up batctl -m bat{{domaene[0]}} if add $IFACE ||:
  52. pre-down batctl -m bat{{domaene[0]}} if del $IFACE ||:
  53. post-down ip link del $IFACE
  54. {% endif %}
  55. {% else %}
  56. {% if indexer.append(indexer.pop() + 1) %}{% endif %}{# increment indexer by 1 #}
  57. auto tap-{{ host }}
  58. iface tap-{{ host }} inet manual
  59. pre-up ip link add $IFACE type gretap local {{ansible_default_ipv4.address}} remote {{hostvars[host].ansible_ssh_host}} dev eth0
  60. pre-up ip link set dev $IFACE address de:ad:be:ef:{{ '%02x' % indexer[0] }}:{{server_id}}
  61. pre-up ip link set $IFACE up
  62. post-up batctl -m bat{{domaene[0]}} if add $IFACE ||:
  63. pre-down batctl -m bat{{domaene[0]}} if del $IFACE ||:
  64. post-down ip link del $IFACE
  65. {% endif %}
  66. {% endfor %}
  67. # END: Domäne-{{domaene[0]}}
  68. {% endfor %}