MEschenbacher's Wireguard Saltstack Formula
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

47 lines
1.3KB

  1. {% from "wireguard/map.jinja" import wireguard with context %}
  2. wireguard:
  3. pkg.installed:
  4. - name: {{ wireguard.package }}
  5. {% for interface, values in salt['pillar.get']('wireguard:interfaces', {}).items() %}
  6. wireguard_{{ interface }}:
  7. wg.present:
  8. - name: {{ interface }}
  9. {% for k, v in values.items() %}
  10. {% if k in ['listen_port', 'fwmark', 'private_key', 'preshared_key'] %}
  11. - {{k}}: {{v}}
  12. {% endif %}
  13. {% endfor %} {# values.items() #}
  14. {% for peer in values.get('peers', {}) %}
  15. wireguard_{{ interface }}_peer_{{ peer.get('peer') }}:
  16. wg.peer_present:
  17. - interface: {{ interface }}
  18. - name: {{ peer.get('peer') }}
  19. {% if peer.get('endpoint') != None %}
  20. - endpoint: '{{ peer.get('endpoint') }}'
  21. {% endif %}
  22. {% if peer.get('persistent_keepalive') != None %}
  23. - persistent_keepalive: {{ peer.get('persistent_keepalive') }}
  24. {% endif %}
  25. {% if peer.get('allowed_ips') != None %}
  26. - allowed_ips:
  27. {% for subnet in peer.get('allowed_ips', []) %}
  28. - {{subnet}}
  29. {% endfor %}
  30. {% endif %}
  31. {% endfor %}
  32. {% endfor %}
  33. {% for interface in salt['pillar.get']('wireguard:set_forward_interfaces', []) %}
  34. net.ipv4.conf.{{interface}}.forwarding:
  35. sysctl.present:
  36. - value: 1
  37. net.ipv6.conf.{{interface}}.forwarding:
  38. sysctl.present:
  39. - value: 1
  40. {% endfor %}