summaryrefslogtreecommitdiff
path: root/roles/install_wireguard_mesh
diff options
context:
space:
mode:
authorNiklas Yann Wettengel <niyawe@niyawe.de>2017-07-05 12:37:39 +0200
committerNiklas Yann Wettengel <niyawe@niyawe.de>2017-07-05 12:37:39 +0200
commit739f97d85908baba47589bb7466a7d559b4424b2 (patch)
tree1498ac048448f8ff53b71017d35d1f89ed08dd4d /roles/install_wireguard_mesh
parentd82f8524972086862f64750f325ba067ea993d86 (diff)
wireguard site mesh
Diffstat (limited to 'roles/install_wireguard_mesh')
-rw-r--r--roles/install_wireguard_mesh/tasks/main.yml28
-rw-r--r--roles/install_wireguard_mesh/templates/down.sh.j26
-rw-r--r--roles/install_wireguard_mesh/templates/up.sh.j215
-rw-r--r--roles/install_wireguard_mesh/templates/wg.conf.j215
4 files changed, 64 insertions, 0 deletions
diff --git a/roles/install_wireguard_mesh/tasks/main.yml b/roles/install_wireguard_mesh/tasks/main.yml
new file mode 100644
index 0000000..1672769
--- /dev/null
+++ b/roles/install_wireguard_mesh/tasks/main.yml
@@ -0,0 +1,28 @@
+---
+- name: create wireguard config for sites
+ template:
+ src: wg.conf.j2
+ dest: /etc/wireguard/wg{{ item.name }}.conf
+ mode: 0400
+ with_items: "{{ sites }}"
+
+- name: create wireguard up scripts for sites
+ template:
+ src: up.sh.j2
+ dest: /etc/wireguard/up{{ item.name }}.sh
+ mode: 0744
+ with_items: "{{ sites }}"
+
+- name: create wireguard down scripts for sites
+ template:
+ src: down.sh.j2
+ dest: /etc/wireguard/down{{ item.name }}.sh
+ mode: 0744
+ with_items: "{{ sites }}"
+
+- name: start and enable wireguard mesh
+ systemd:
+ name: wg-quick@wg{{ item.name }}.service
+ enabled: yes
+ state: started
+ with_items: "{{ sites }}"
diff --git a/roles/install_wireguard_mesh/templates/down.sh.j2 b/roles/install_wireguard_mesh/templates/down.sh.j2
new file mode 100644
index 0000000..29d4fb7
--- /dev/null
+++ b/roles/install_wireguard_mesh/templates/down.sh.j2
@@ -0,0 +1,6 @@
+#!/bin/bash
+{% for peer in item.wireguard_mesh_peers %}
+batctl -m bat0 if del mesh{{ item.name }}{{ peer.number }}
+ip link set down dev mesh{{ item.name }}{{ peer.number }}
+ip link del mesh{{ item.name }}{{ peer.number }} type ip6gretap
+{% endfor %}
diff --git a/roles/install_wireguard_mesh/templates/up.sh.j2 b/roles/install_wireguard_mesh/templates/up.sh.j2
new file mode 100644
index 0000000..cdab474
--- /dev/null
+++ b/roles/install_wireguard_mesh/templates/up.sh.j2
@@ -0,0 +1,15 @@
+#!/bin/bash
+{% for peer in item.wireguard_mesh_peers %}
+ip link add mesh{{ item.name }}{{ peer.number }} type ip6gretap remote {{ peer.address }} local {{ item.wireguard_mesh_address }} ttl 255 dev wg{{ item.name }}
+ip link set mtu 1280 dev mesh{{ item.name }}{{ peer.number }}
+ip link set address {{ peer.mac }} dev mesh{{ item.name }}{{ peer.number }}
+ip link set up dev mesh{{ item.name }}{{ peer.number }}
+batctl -m bat{{ item.name }} if add mesh{{ item.name }}{{ peer.number }}
+{% endfor %}
+batctl -m bat{{ item.name }} gw server 1000000/1000000
+batctl -m bat{{ item.name }} it 10000
+batctl -m bat{{ item.name }} mm 1
+echo 64 > /sys/class/net/bat{{ item.name }}/mesh/hop_penalty
+netctl start bat{{ item.name }}
+systemctl restart dhcpd4.service
+systemctl restart named.service
diff --git a/roles/install_wireguard_mesh/templates/wg.conf.j2 b/roles/install_wireguard_mesh/templates/wg.conf.j2
new file mode 100644
index 0000000..e3af3f2
--- /dev/null
+++ b/roles/install_wireguard_mesh/templates/wg.conf.j2
@@ -0,0 +1,15 @@
+[Interface]
+ListenPort = {{ item.wireguard_mesh_port }}
+PrivateKey = {{ item.wireguard_mesh_key }}
+Address = {{ item.wireguard_mesh_address }}/48
+MTU = 1400
+PostUp = /etc/wireguard/up{{ item.name }}.sh
+PreDown = /etc/wireguard/down{{ item.name }}.sh
+
+{% for peer in item.wireguard_mesh_peers %}
+[Peer]
+PublicKey = {{ peer.key }}
+AllowedIPs = {{ peer.address }}/128
+Endpoint = [{{ peer.endpoint }}]:{{ item.wireguard_mesh_port }}
+PersistentKeepalive = 30
+{% endfor %}