MEschenbacher's Wireguard Saltstack Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3KB

  1. {% from "wireguard/map.jinja" import wireguard with context %}
  2. {% for interface, values in salt['pillar.get']('wireguard:interfaces', {}).items() %}
  3. wireguard_{{ interface }}:
  4. wg.present:
  5. - name: {{ interface }}
  6. {% for k, v in values.items() %}
  7. {% if k in ['listen_port', 'fwmark', 'private_key'] %}
  8. - {{k}}: {{v}}
  9. {% endif %}
  10. {% endfor %} {# values.items() #}
  11. {% for peer in values.get('peers', {}) %}
  12. wireguard_{{ interface }}_peer_{{ peer.get('peer') }}:
  13. wg.peer_present:
  14. - interface: {{ interface }}
  15. - name: {{ peer.get('peer') }}
  16. {% if peer.get('endpoint') != None %}
  17. - endpoint: '{{ peer.get('endpoint') }}'
  18. {% endif %}
  19. {% if peer.get('persistent_keepalive') != None %}
  20. - persistent_keepalive: {{ peer.get('persistent_keepalive') }}
  21. {% endif %}
  22. {% if peer.get('allowed_ips') != None %}
  23. - allowed_ips:
  24. {% for subnet in peer.get('allowed_ips', []) %}
  25. - {{subnet}}
  26. {% endfor %}
  27. {% if peer.get('preshared_key') != None %}
  28. - preshared_key: {{ peer.get('preshared_key') }}
  29. {% endif %}
  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 %}