restart-vpn.yml 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ---
  2. - hosts: dhcp
  3. become: True
  4. gather_facts: False
  5. tasks:
  6. - name: Load potential endpoints
  7. include_vars:
  8. file: ../vars/vault.yaml
  9. - name: Select a random endpoint
  10. set_fact:
  11. wg_info: "{{ vaulted_wg_info | shuffle | first }}"
  12. - name: Update settings to connect to {{ wg_info.name }}
  13. set_fact:
  14. wg_private_key: "{{ wg_info.private_key }}"
  15. wg_address: "{{ wg_info.address }}"
  16. wg_public_key: "{{ wg_info.pubkey }}"
  17. wg_endpoint: "{{ wg_info.endpoint }}"
  18. - name: Update wireguard config
  19. template:
  20. src: ../roles/wg-gateway/templates/wg.conf.j2
  21. dest: /etc/wireguard/{{ wg_interface }}.conf
  22. owner: root
  23. group: root
  24. mode: '0644'
  25. - name: Restart wireguard interface
  26. systemd:
  27. name: wg-quick@{{ wg_interface }}
  28. state: restarted
  29. - name: Edit /etc/motd
  30. lineinfile:
  31. path: /etc/motd
  32. regex: "^VPN Traffic tunneled through server: "
  33. line: "VPN Traffic tunneled through server: {{ wg_info.name }}"
  34. delegate_to: nas
  35. - name: Restart unbound
  36. systemd:
  37. name: unbound
  38. state: restarted