From b419094cda74405eb4cbb8b7031b53cd2f347566 Mon Sep 17 00:00:00 2001 From: binary Date: Thu, 12 Nov 2020 14:29:49 +0100 Subject: Refactor and cleanup old roles --- roles/wireguard/templates/dcontroller.conf.j2 | 19 +++++++++++++++++++ roles/wireguard/templates/host.conf.j2 | 15 +++++++++++++++ roles/wireguard/templates/hostname.tun0.j2 | 9 +++++++++ 3 files changed, 43 insertions(+) create mode 100644 roles/wireguard/templates/dcontroller.conf.j2 create mode 100644 roles/wireguard/templates/host.conf.j2 create mode 100644 roles/wireguard/templates/hostname.tun0.j2 (limited to 'roles/wireguard/templates') diff --git a/roles/wireguard/templates/dcontroller.conf.j2 b/roles/wireguard/templates/dcontroller.conf.j2 new file mode 100644 index 0000000..c1fd887 --- /dev/null +++ b/roles/wireguard/templates/dcontroller.conf.j2 @@ -0,0 +1,19 @@ + +# wireguard client configuration ~~ /etc/wireguard/*.conf +# managed by Ansible +{% set dcontroller_keys = lookup("file", wg_dcontroller_keys).splitlines() %} + +[Interface] +#Address = {{ ip.in }}, fd00::1/128 +ListenPort = 53 +PrivateKey = {{ dcontroller_keys[0] }} + +{% for host in groups["all"] if hostvars[host].ansible_host != _i.dcontroller %} +{% set host = hostvars[host] %} +{% set host_keys = lookup("file", wg_dir + "/" + host.ansible_host + ".keys").splitlines() %} +# {{ host.ansible_host }} +[Peer] +PublicKey = {{ host_keys[1] }} +AllowedIPs = {{ host.ip.in }}/32, fd00:10:10::{{ host.ip.in.split('.')[3] }}/128 + +{% endfor %} diff --git a/roles/wireguard/templates/host.conf.j2 b/roles/wireguard/templates/host.conf.j2 new file mode 100644 index 0000000..c25d937 --- /dev/null +++ b/roles/wireguard/templates/host.conf.j2 @@ -0,0 +1,15 @@ + +# wireguard client configuration ~~ /etc/wireguard/*.conf +# managed by Ansible +{% set host_keys = lookup("file", wg_host_keys).splitlines() %} +{% set dcontroller_keys = lookup("file", wg_dcontroller_keys).splitlines() %} + +[Interface] +Address = {{ ip.in }} +PrivateKey = {{ host_keys[0] }} + +[Peer] +PublicKey = {{ dcontroller_keys[1] }} +Endpoint = {{ hostvars[_i.dcontroller].ip.out }}:53 +AllowedIPs = 0.0.0.0/0, ::/0 +PersistentKeepalive = 25 diff --git a/roles/wireguard/templates/hostname.tun0.j2 b/roles/wireguard/templates/hostname.tun0.j2 new file mode 100644 index 0000000..3903ccb --- /dev/null +++ b/roles/wireguard/templates/hostname.tun0.j2 @@ -0,0 +1,9 @@ +inet 10.10.0.1 255.255.255.0 +inet6 fd00:10:10::1 +!/usr/local/bin/wireguard-go -f tun0 & +!/bin/sleep 2 +!/usr/local/bin/wg setconf tun0 /etc/wireguard/{{ _i.dcontroller }}.conf +!/bin/sleep 2 +!/sbin/route add -inet 10.10.0.0/24 10.10.0.1 +!/bin/sleep 2 +!/sbin/route add -inet6 fd00:10:10::/64 fd00:10:10::1 -- cgit v1.2.3