Reworked wireguard configurations
parent
1d7840422f
commit
768cb0cfb4
@ -1,7 +1,26 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: Install wireguard vpn
|
- name: Configure wireguard backbones
|
||||||
hosts: all
|
hosts: wireguard_backbones
|
||||||
strategy: free
|
strategy: linear
|
||||||
roles:
|
roles:
|
||||||
- role: wireguard/application
|
- role: wireguard/backbone
|
||||||
|
|
||||||
|
- name: Configure wireguard clients
|
||||||
|
hosts: wireguard_clients
|
||||||
|
strategy: linear
|
||||||
|
roles:
|
||||||
|
- role: wireguard/client
|
||||||
|
|
||||||
|
- name: Reload all configurations
|
||||||
|
hosts:
|
||||||
|
- wireguard_backbones
|
||||||
|
- wireguard_clients
|
||||||
|
roles:
|
||||||
|
- role: wireguard/handlers
|
||||||
|
tasks:
|
||||||
|
- name: Reload wireguard configuration always
|
||||||
|
become: no
|
||||||
|
command: /bin/true
|
||||||
|
delegate_to: localhost
|
||||||
|
notify: reassemble wireguard config
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
wireguard_key_directory: "/root/wireguard"
|
wireguard_key_directory: "{{ global_wireguard_configuration_environment_directory }}/key"
|
||||||
wireguard_private_key: "{{ wireguard_key_directory }}/wg-private.key"
|
wireguard_private_key: "{{ wireguard_key_directory }}/private"
|
||||||
wireguard_public_key: "{{ wireguard_key_directory }}/wg-public.key"
|
wireguard_public_key: "{{ wireguard_key_directory }}/public"
|
||||||
|
|
||||||
|
wireguard_interface_name: "wg0"
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euxo pipefail;
|
||||||
|
|
||||||
|
INTERFACE={{ wireguard_interface_name | quote }};
|
||||||
|
|
||||||
|
ip route flush dev $INTERFACE;
|
||||||
|
ip link set down dev $INTERFACE;
|
||||||
|
ip address flush dev $INTERFACE;
|
@ -0,0 +1,6 @@
|
|||||||
|
[Peer]
|
||||||
|
{% if wireguard_public_address != '127.1' %}
|
||||||
|
Endpoint = {{ wireguard_public_address }}:{{ global_wireguard_port }}
|
||||||
|
{% endif %}
|
||||||
|
PublicKey = {{ lookup('file', global_wireguard_public_directory + '/' + inventory_hostname) }}
|
||||||
|
AllowedIPs = {{ wireguard_ipv4_address }}, {{ global_wireguard_ipv4_range }}
|
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euxo pipefail;
|
||||||
|
|
||||||
|
INTERFACE={{ wireguard_interface_name | quote }};
|
||||||
|
|
||||||
|
if ! ip link show dev $INTERFACE; then
|
||||||
|
ip link add dev $INTERFACE type wireguard;
|
||||||
|
else
|
||||||
|
ip link set dev $INTERFACE type wireguard;
|
||||||
|
fi
|
||||||
|
ip address add dev $INTERFACE {{ wireguard_ipv4_address | quote }}/{{ global_wireguard_ipv4_subnet | quote }};
|
||||||
|
wg setconf $INTERFACE {{ global_wireguard_configuration_directory }}/wireguard.cfg;
|
||||||
|
ip link set up dev $INTERFACE;
|
||||||
|
#ip route add {{ global_wireguard_ipv4_range }} dev $INTERFACE;
|
@ -0,0 +1,3 @@
|
|||||||
|
[Interface]
|
||||||
|
PrivateKey = <PRIVATEKEY>
|
||||||
|
ListenPort = {{ global_wireguard_port }}
|
@ -0,0 +1,8 @@
|
|||||||
|
dest:={{ global_wireguard_configuration_link_name }}
|
||||||
|
|
||||||
|
peer_files:=$(wildcard peers/*)
|
||||||
|
|
||||||
|
${dest}/wireguard.cfg: main.cfg ${peer_files}
|
||||||
|
cat $^ | sed '0,/<PRIVATEKEY>/{s#<PRIVATEKEY>#'"$$(cat {{ wireguard_private_key | quote }})"'#}' > "$@"
|
||||||
|
chown root:root "$@"
|
||||||
|
chmod u=rw,g=r,o= "$@"
|
@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=WireGuard Interface
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart={{ global_wireguard_configuration_directory }}/up.sh
|
||||||
|
RemainAfterExit=true
|
||||||
|
ExecStop={{ global_wireguard_configuration_directory }}/down.sh
|
||||||
|
StandardOutput=journal
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
# wireguard_ipv4_address
|
||||||
|
wireguard_public_address: "{{ inventory_hostname }}"
|
||||||
|
|
||||||
|
allowed_ips:
|
||||||
|
- "{{ global_wireguard_ipv4_range }}"
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
allow_duplicates: no
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
- role: misc/handlers
|
||||||
|
- role: wireguard/application
|
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Allow wireguard on firewall
|
||||||
|
ufw:
|
||||||
|
rule: allow
|
||||||
|
port: "{{ global_wireguard_port }}"
|
||||||
|
proto: udp
|
||||||
|
|
||||||
|
- name: Store public key to backbones
|
||||||
|
copy:
|
||||||
|
src: "{{ global_wireguard_peers_directory }}/{{ inventory_hostname }}"
|
||||||
|
dest: "{{ global_wireguard_configuration_environment_directory }}/peers/{{ inventory_hostname }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "u=rw,g=r,o=r"
|
||||||
|
delegate_to: "{{ item }}"
|
||||||
|
when: "item != inventory_hostname"
|
||||||
|
loop: "{{ groups['wireguard_backbones'] }}"
|
@ -0,0 +1 @@
|
|||||||
|
../../application/templates/peer.cfg
|
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
# wireguard_ipv4_address
|
||||||
|
|
||||||
|
keepalive_timeout: 25
|
||||||
|
|
||||||
|
allowed_ips:
|
||||||
|
- "{{ global_wireguard_ipv4_range }}"
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
allow_duplicates: no
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
- role: wireguard/application
|
@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Add config of backbones
|
||||||
|
copy:
|
||||||
|
content: |
|
||||||
|
{{ lookup('file', global_wireguard_peers_directory + '/' + item) }}
|
||||||
|
PersistentKeepalive = {{ keepalive_timeout }}
|
||||||
|
dest: "{{ global_wireguard_configuration_environment_directory }}/peers/{{ item }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "u=rw,g=r,o=r"
|
||||||
|
when: "item != inventory_hostname"
|
||||||
|
loop: "{{ groups['wireguard_backbones'] }}"
|
||||||
|
notify: reassemble wireguard config
|
||||||
|
|
||||||
|
- name: Store public key to backbones
|
||||||
|
copy:
|
||||||
|
src: "{{ global_wireguard_peers_directory }}/{{ inventory_hostname }}"
|
||||||
|
dest: "{{ global_wireguard_configuration_environment_directory }}/peers/{{ inventory_hostname }}"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "u=rw,g=r,o=r"
|
||||||
|
delegate_to: "{{ item }}"
|
||||||
|
when: "item != inventory_hostname"
|
||||||
|
loop: "{{ groups['wireguard_backbones'] }}"
|
@ -0,0 +1 @@
|
|||||||
|
../../application/templates/peer.cfg
|
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
wireguard_public_address: "127.1"
|
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: reassemble wireguard config
|
||||||
|
make:
|
||||||
|
chdir: "{{ global_wireguard_configuration_environment_directory }}"
|
||||||
|
target: "{{ global_wireguard_configuration_link_name }}/wireguard.cfg"
|
||||||
|
notify:
|
||||||
|
- reload wireguard interface
|
||||||
|
|
||||||
|
- name: reload wireguard interface
|
||||||
|
systemd:
|
||||||
|
name: wireguard
|
||||||
|
state: restarted
|
Loading…
Reference in New Issue