main.yml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ---
  2. - name: Ensure permission on OpenVPN directory
  3. become: true
  4. file:
  5. path: /etc/stunnel
  6. state: directory
  7. mode: 0700
  8. owner: stunnel4
  9. group: stunnel4
  10. - name: Install stunnel configuration
  11. become: true
  12. template:
  13. src: templates/config.j2
  14. dest: "/etc/stunnel/{{ item.name }}.conf"
  15. mode: 0600
  16. owner: stunnel4
  17. group: stunnel4
  18. loop: "{{ stunnel | flatten(levels=1) }}"
  19. - name: Install local keys
  20. become: true
  21. copy:
  22. content: "{{ item.key }}"
  23. dest: "/etc/stunnel/{{ item.name }}.pem"
  24. mode: 0600
  25. owner: stunnel4
  26. group: stunnel4
  27. loop: "{{ stunnel | flatten(levels=1) }}"
  28. - name: Install local certificates
  29. become: true
  30. copy:
  31. content: "{{ item.certificate }}"
  32. dest: "/etc/stunnel/{{ item.name }}.crt"
  33. mode: 0600
  34. owner: stunnel4
  35. group: stunnel4
  36. loop: "{{ stunnel | flatten(levels=1) }}"
  37. - name: Install local remote
  38. become: true
  39. copy:
  40. content: "{{ item.remote_certificate }}"
  41. dest: "/etc/stunnel/{{ item.name }}_remote.crt"
  42. mode: 0600
  43. owner: stunnel4
  44. group: stunnel4
  45. loop: "{{ stunnel | flatten(levels=1) }}"
  46. - name: Enable autostart
  47. become: true
  48. systemd:
  49. name: "stunnel@{{ item.name }}"
  50. masked: false
  51. enabled: true
  52. when: item.autostart
  53. loop: "{{ stunnel | flatten(levels=1) }}"
  54. - name: Disable autostart
  55. become: true
  56. systemd:
  57. name: "stunnel@{{ item.name }}"
  58. masked: false
  59. enabled: false
  60. when: not item.autostart
  61. loop: "{{ stunnel | flatten(levels=1) }}"