task_machine_configuration.yml 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. cmd: "wg genkey | tee /etc/wireguard/privatekey | wg pubkey | tee /etc/wireguard/publickey"
  9. - name: "20: Modify Private key permissions"
  10. ansible.builtin.file:
  11. path: "/etc/wireguard/privatekey"
  12. mode: '0600'
  13. - name: "30: Set VPN configuration variables"
  14. ansible.builtin.command: cat /etc/wireguard/privatekey
  15. register: private_key_cmd
  16. - name: "35: Register the stdout of previous"
  17. ansible.builtin.set_fact:
  18. vpn_private_key_content: "{{ private_key_cmd.stdout }}"
  19. - name: "40: Create server configuration file"
  20. ansible.builtin.template:
  21. src: "templates/wg0.conf.j2"
  22. dest: "/etc/wireguard/wg0.conf"
  23. - name: "50: Modify Server config file permissions"
  24. ansible.builtin.file:
  25. path: "/etc/wireguard/wg0.conf"
  26. mode: "0600"
  27. ansible.builtin.file:
  28. path: "/etc/wireguard/privatekey"
  29. mode: "0600"
  30. - name: "60: Start the wireguard server"
  31. ansible.builtin.shell:
  32. cmd: "wg-quick up wg0"
  33. - name: "70: Enable IP forwarding"
  34. ansible.builtin.sysctl:
  35. name: "net.ipv4.ip_forward"
  36. value: "1"
  37. sysctl_set: "yes"
  38. state: "present"
  39. reload: "yes"