configuration.yml 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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"