restart-vpn.yml 1.2 KB

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