2021-05-07 04:24:52 +00:00
|
|
|
- name: Install WireGuard
|
|
|
|
apt:
|
|
|
|
name: wireguard
|
|
|
|
state: present
|
|
|
|
update_cache: true
|
|
|
|
|
|
|
|
- name: Generate WireGuard keys
|
|
|
|
shell: wg genkey | tee privatekey | wg pubkey > publickey
|
|
|
|
args:
|
|
|
|
chdir: /etc/wireguard/
|
|
|
|
creates: /etc/wireguard/privatekey
|
|
|
|
|
|
|
|
- name: Grab WireGuard private key for configuration
|
|
|
|
slurp:
|
|
|
|
src: /etc/wireguard/privatekey
|
|
|
|
register: wgkey
|
|
|
|
|
|
|
|
- name: Install WireGuard configuration
|
|
|
|
template:
|
|
|
|
src: wireguard.j2
|
|
|
|
dest: /etc/wireguard/wg0.conf
|
2021-05-07 06:38:49 +00:00
|
|
|
notify:
|
|
|
|
- restart_wireguard
|
2021-05-07 04:24:52 +00:00
|
|
|
|
|
|
|
- name: Start WireGuard interface
|
|
|
|
service:
|
|
|
|
name: wg-quick@wg0
|
|
|
|
state: started
|
|
|
|
enabled: true
|
2022-08-13 04:19:24 +00:00
|
|
|
|
|
|
|
- name: Add WireGuard firewall rule
|
|
|
|
ufw:
|
|
|
|
rule: allow
|
|
|
|
port: "{{ wireguard.listenport }}"
|
|
|
|
proto: tcp
|
|
|
|
when: wireguard.listenport is defined
|