2020-12-02 16:09:55 +01:00
|
|
|
---
|
2020-12-03 00:09:24 +01:00
|
|
|
- name: Update APT package cache
|
2020-12-02 16:09:55 +01:00
|
|
|
apt:
|
|
|
|
update_cache: true
|
2020-12-03 00:09:24 +01:00
|
|
|
upgrade: dist
|
|
|
|
|
|
|
|
- name: Ensure WireGuard DKMS package is removed
|
2020-12-02 16:09:55 +01:00
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
- "wireguard-dkms"
|
|
|
|
state: absent
|
|
|
|
|
2020-12-02 18:11:18 +01:00
|
|
|
- name: Install wireguard package
|
2020-12-02 16:09:55 +01:00
|
|
|
apt:
|
|
|
|
name: "wireguard"
|
|
|
|
state: present
|
|
|
|
|
2020-12-02 18:11:18 +01:00
|
|
|
- name: Install qrencode package
|
|
|
|
apt:
|
|
|
|
name: "qrencode"
|
|
|
|
state: present
|
|
|
|
|
2020-12-03 00:09:24 +01:00
|
|
|
- name: ensure wireguard services are stopped
|
|
|
|
command: "systemctl stop wg-quick@wg0"
|
|
|
|
|
2020-12-27 14:25:20 +01:00
|
|
|
- name: generate directory for server configs
|
|
|
|
file:
|
|
|
|
path: "~/wg/wireguard-server"
|
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0700
|
|
|
|
|
2020-12-02 18:11:18 +01:00
|
|
|
- name: generate directories for client configs
|
|
|
|
file:
|
2020-12-27 14:25:20 +01:00
|
|
|
path: "~/wg/{{ item }}"
|
2020-12-02 18:11:18 +01:00
|
|
|
state: directory
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0700
|
2020-12-27 14:25:20 +01:00
|
|
|
with_items: "{{ vpn_client_names }}"
|
2020-12-02 18:11:18 +01:00
|
|
|
|
2020-12-27 14:25:20 +01:00
|
|
|
- name: generate private key for the server
|
|
|
|
shell: umask 077; wg genkey | tee ~/wg/wireguard-server.private
|
|
|
|
register: vpn_server_private_key
|
2020-12-02 18:11:18 +01:00
|
|
|
|
2020-12-27 14:25:20 +01:00
|
|
|
- name: generate public key for the server
|
|
|
|
shell: umask 077; cat ~/wg/wireguard-server.private | wg pubkey | tee ~/wg/wireguard-server.public
|
|
|
|
register: vpn_server_public_key
|
|
|
|
|
|
|
|
- name: generate private keys for clients
|
|
|
|
shell: umask 077; wg genkey | tee ~/wg/{{ item }}/wg0.private
|
|
|
|
register: vpn_client_private_keys
|
|
|
|
with_items: "{{ vpn_client_names }}"
|
2020-12-02 18:11:18 +01:00
|
|
|
|
2020-12-27 14:25:20 +01:00
|
|
|
- name: generate public keys for clients
|
|
|
|
shell: umask 077; cat ~/wg/{{ item }}/wg0.private | wg pubkey | tee ~/wg/{{ item }}/wg0.public
|
|
|
|
register: vpn_client_public_keys
|
|
|
|
with_items: "{{ vpn_client_names }}"
|
2020-12-02 18:11:18 +01:00
|
|
|
|
|
|
|
- name: generate client configs
|
|
|
|
template:
|
|
|
|
src: "wg0-client.conf"
|
2020-12-28 18:21:19 +01:00
|
|
|
dest: "~/wg/{{ item.1.item }}/wg0-client.conf"
|
2020-12-02 18:11:18 +01:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0600
|
2020-12-28 18:21:19 +01:00
|
|
|
with_indexed_items: "{{ vpn_client_private_keys.results }}"
|
2020-12-02 18:11:18 +01:00
|
|
|
|
|
|
|
- name: generate qr codes for client configs
|
2020-12-27 14:25:20 +01:00
|
|
|
shell: umask 077; qrencode --type=PNG --output=/root/wg/{{ item }}/wg0-client.png < ~/wg/{{ item }}/wg0-client.conf
|
|
|
|
with_items: "{{ vpn_client_names }}"
|
2020-12-02 18:11:18 +01:00
|
|
|
|
|
|
|
- name: generate server config
|
|
|
|
template:
|
|
|
|
src: "wg0.conf"
|
|
|
|
dest: "/etc/wireguard/wg0.conf"
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0600
|
|
|
|
|
|
|
|
- name: enable ipv4 traffic forwarding
|
|
|
|
sysctl:
|
|
|
|
name: net.ipv4.ip_forward
|
|
|
|
value: "1"
|
|
|
|
sysctl_set: yes
|
|
|
|
state: present
|
|
|
|
reload: yes
|
|
|
|
|
2020-12-03 00:09:24 +01:00
|
|
|
- name: ensure wireguard services are enabled
|
|
|
|
command: "systemctl enable wg-quick@wg0"
|
|
|
|
|
2020-12-02 18:11:18 +01:00
|
|
|
- name: ensure all wireguard services are started
|
2020-12-03 00:09:24 +01:00
|
|
|
command: "systemctl start wg-quick@wg0"
|
2020-12-02 19:12:01 +01:00
|
|
|
|
2020-12-02 18:11:18 +01:00
|
|
|
- name: download client conf files to the "wireguard_profiles/" folder on your local host
|
|
|
|
fetch:
|
2020-12-27 14:25:20 +01:00
|
|
|
src: "~/wg/{{item}}/wg0-client.conf"
|
|
|
|
dest: "wireguard_profiles/{{ ansible_ssh_host }}/{{item}}/"
|
2020-12-02 18:11:18 +01:00
|
|
|
flat: yes
|
2020-12-27 14:25:20 +01:00
|
|
|
with_items: "{{ vpn_client_names }}"
|
2020-12-02 18:11:18 +01:00
|
|
|
|
2020-12-27 14:25:20 +01:00
|
|
|
- name: download client conf files to the "wireguard_profiles/" folder on your local host
|
2020-12-02 18:11:18 +01:00
|
|
|
fetch:
|
2020-12-27 14:25:20 +01:00
|
|
|
src: "~/wg/{{item}}/wg0-client.png"
|
|
|
|
dest: "wireguard_profiles/{{ ansible_ssh_host }}/{{item}}/"
|
2020-12-02 18:11:18 +01:00
|
|
|
flat: yes
|
2020-12-27 14:25:20 +01:00
|
|
|
with_items: "{{ vpn_client_names }}"
|