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.

44 lines
1.2KB

  1. {%- for interface in salt['pillar.get']('wireguard', {}).keys() %}
  2. {% if salt['pillar.get']('wireguard:' ~ interface ~ ':delete', False) %}
  3. stop and disable wg-quick@{{interface}}:
  4. service.dead:
  5. - name: wg-quick@{{interface}}
  6. - enable: False
  7. remove wireguard_interface_{{interface}}:
  8. file.absent:
  9. - name: /etc/wireguard/{{interface}}.conf
  10. {% elif not salt['pillar.get']('wireguard:' ~ interface ~ ':enable', True) %}
  11. stop and disable wg-quick@{{interface}}:
  12. service.dead:
  13. - name: wg-quick@{{interface}}
  14. - enable: False
  15. {% else %}
  16. {% if salt['pillar.get']('wireguard:' ~ interface ~ ':config') %}
  17. wireguard_interface_{{interface}}_config:
  18. file.managed:
  19. - name: /etc/wireguard/{{interface}}.conf
  20. - contents_pillar: wireguard:{{interface}}:config
  21. - mode: 600
  22. {% else %}
  23. wireguard_interface_{{interface}}_config:
  24. file.managed:
  25. - name: /etc/wireguard/{{interface}}.conf
  26. - source: salt://wireguard/files/wg.conf
  27. - template: jinja2
  28. - context:
  29. interface: {{interface}}
  30. - mode: 600
  31. {% endif %}
  32. restart wg-quick@{{interface}}:
  33. service.running:
  34. - name: wg-quick@{{interface}}
  35. - enable: True
  36. - watch:
  37. - file: wireguard_interface_{{interface}}_config
  38. {% endif %}
  39. {%- endfor %}