configuration.yml 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ---
  2. - name: "00: Create Wireguard directory"
  3. ansible.builtin.file:
  4. path: "/etc/wireguard"
  5. state: "directory"
  6. - name: "10: Create Public and Private server keys"
  7. ansible.builtin.shell:
  8. command: "wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey"
  9. become: True
  10. - name: "20: Modify Private key permissions"
  11. ansible.builtin.file:
  12. path: "/etc/wireguard/privatekey"
  13. mode: '0600'
  14. - name: "30: Set VPN configuration variables"
  15. become: True
  16. ansible.builtin.set_fact:
  17. vpn_network_address: "{{ vpn_network_address }}"
  18. vpn_server_port: "{{ vpn_server_port }}"
  19. vpn_private_key_content: "{{ lookup('ansible.builtin.file', '/etc/wireguard/privatekey') }}"
  20. - name: "40: Create server configuration file"
  21. become: True
  22. ansible.builtin.template:
  23. src: "templates/wg0.conf.j2"
  24. dest: "/etc/wireguard/wg0.conf"
  25. - name: "50: Modify Server config file permissions"
  26. become: True
  27. ansible.builtin.file:
  28. path: "/etc/wireguard/wg0.conf"
  29. mode: "0600"
  30. ansible.builtin.file:
  31. path: "/etc/wireguard/privatekey"
  32. mode: "0600"
  33. - name: "60: Start the wireguard server"
  34. become: True
  35. ansible.builtin.shell:
  36. cmd: "wg-quick up wg0"
  37. - name: "70: Enable IP forwarding"
  38. become: True
  39. ansible.builtin.sysctl:
  40. name: "net.ipv4.ip_forward"
  41. value: "1"
  42. sysctl_set: "yes"
  43. state: "present"
  44. reload: "yes"