blob: a26155665ebe88a7e54184377aa4ab9790dc466e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
- name: Install WireGuard
package:
state: present
name: "{{ wireguard_os_packages[ansible_distribution] }}"
tags:
- role::wireguard
- name: Create firewalld zone for Wireguard on Rocky hosts
ansible.posix.firewalld:
zone: wireguard
state: present
permanent: true
when: ansible_distribution == "Rocky"
tags:
- role::wireguard
- name: Add wg0 interface to wireguard firewalld zone
ansible.posix.firewalld:
zone: wireguard
interface: wg0
state: enabled
permanent: true
when: ansible_distribution == "Rocky"
tags:
- role::wireguard
- name: Generate WireGuard private key
shell: set -o pipefail && wg genkey > /etc/wireguard/key.priv
args:
executable: /bin/bash
creates: /etc/wireguard/key.priv
tags:
- role::wireguard
- name: Generate WireGuard public key
shell: set -o pipefail && cat /etc/wireguard/key.priv | wg pubkey > /etc/wireguard/key.pub
args:
executable: /bin/bash
creates: /etc/wireguard/key.pub
tags:
- role::wireguard
- name: Ensure file permissions for keys set correctly
file:
path: "{{ item }}"
owner: root
group: root
mode: "0600"
with_items:
- /etc/wireguard/key.priv
- /etc/wireguard/key.pub
tags:
- role::wireguard
- name: Fetch private key for all hosts
slurp:
src: /etc/wireguard/key.priv
register: wg_priv_key
tags:
- role::wireguard
- name: Fetch public key for all hosts
slurp:
src: /etc/wireguard/key.pub
register: wg_pub_key
tags:
- role::wireguard
- name: Generate WireGuard configuration file
template:
src: wg0.conf.j2
dest: /etc/wireguard/wg0.conf
mode: "0600"
group: root
owner: root
notify:
- Reload wg-quick
tags:
- role::wireguard
- name: Start and enable the WireGuard service
service:
name: wg-quick@wg0
enabled: true
state: started
tags:
- role::wireguard
|