aboutsummaryrefslogtreecommitdiffstats
path: root/roles/wireguard/tasks
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2022-01-11 00:45:31 +0000
committerGravatar Joe Banks <[email protected]>2022-01-11 13:29:08 +0000
commit8861a6c68feb65c69e966a494507be2cc63fe9c0 (patch)
tree5cf61f5dfa8a4179f646aa55d2893f25abe3363c /roles/wireguard/tasks
parentAutomatically add new issues to the project board (#12) (diff)
Add role for setting up WireGuard mesh network
Diffstat (limited to 'roles/wireguard/tasks')
-rw-r--r--roles/wireguard/tasks/main.yml54
1 files changed, 54 insertions, 0 deletions
diff --git a/roles/wireguard/tasks/main.yml b/roles/wireguard/tasks/main.yml
new file mode 100644
index 0000000..66d35a4
--- /dev/null
+++ b/roles/wireguard/tasks/main.yml
@@ -0,0 +1,54 @@
+- name: Install WireGuard
+ apt:
+ update_cache: true
+ cache_valid_time: 3600
+ pkg:
+ - wireguard
+ - wireguard-tools
+ - linux-headers-{{ ansible_kernel }}
+
+- name: Generate WireGuard private key
+ shell: set -o pipefail && wg genkey > /etc/wireguard/key.priv
+ args:
+ executable: /bin/bash
+ creates: /etc/wireguard/key.priv
+
+- 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
+
+- 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
+
+- name: Fetch private key for all hosts
+ slurp:
+ src: /etc/wireguard/key.priv
+ register: wg_priv_key
+
+- name: Fetch public key for all hosts
+ slurp:
+ src: /etc/wireguard/key.pub
+ register: wg_pub_key
+
+- name: Generate WireGuard configuration file
+ template:
+ src: wg0.conf.j2
+ dest: /etc/wireguard/wg0.conf
+ mode: '0600'
+ group: root
+ owner: root
+
+- name: Start and enable the WireGuard service
+ service:
+ name: wg-quick@wg0
+ enabled: true
+ state: started