MEschenbacher's Wireguard Saltstack Formula
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

47 lines
1.4KB

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