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