task_machine_configuration.yml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ---
  2. - name: "00: UFW configuration"
  3. ansible.builtin.command: ufw allow "{{ vpn_server_port }}/udp"
  4. - name: "00: more UFW configuration"
  5. ansible.builtin.command: ufw allow "OpenSSH"
  6. - name: "10: Cycle UFW"
  7. ansible.builtin.command: ufw disable && ufw --force enable
  8. - name: "00: Create Wireguard directory"
  9. ansible.builtin.file:
  10. path: "/etc/wireguard"
  11. state: "directory"
  12. - name: "10: Create Public and Private server keys"
  13. ansible.builtin.shell:
  14. cmd: "wg genkey | tee /etc/wireguard/privatekey | wg pubkey | tee /etc/wireguard/publickey"
  15. - name: "20: Modify Private key permissions"
  16. ansible.builtin.file:
  17. path: "/etc/wireguard/privatekey"
  18. mode: '0600'
  19. - name: "30: Read out VPN server private key"
  20. ansible.builtin.command: cat /etc/wireguard/privatekey
  21. register: private_key_cmd
  22. - name: "35: Register the stdout of previous"
  23. ansible.builtin.set_fact:
  24. vpn_private_key_content: "{{ private_key_cmd.stdout }}"
  25. - name : "40: Read out VPN server public key"
  26. ansible.builtin.command: cat /etc/wireguard/publickey
  27. register: public_key_cmd
  28. - name: "35: Register the stdout of previous"
  29. ansible.builtin.set_fact:
  30. vpn_public_key_content: "{{ public_key_cmd.stdout }}"
  31. - name: "40: Create server configuration file"
  32. ansible.builtin.template:
  33. src: "templates/wg0.conf.j2"
  34. dest: "/etc/wireguard/wg0.conf"
  35. - name: "50: Modify Server config file permissions"
  36. ansible.builtin.file:
  37. path: "/etc/wireguard/wg0.conf"
  38. mode: "0600"
  39. ansible.builtin.file:
  40. path: "/etc/wireguard/privatekey"
  41. mode: "0600"
  42. - name: "60: Start the wireguard server"
  43. ansible.builtin.shell:
  44. cmd: "wg-quick up wg0"
  45. - name: "70: Enable IP forwarding"
  46. ansible.builtin.sysctl:
  47. name: "net.ipv4.ip_forward"
  48. value: "1"
  49. sysctl_set: "yes"
  50. state: "present"
  51. reload: "yes"