From c7b48bed66e00547e400f22d3024fd81947b318f Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Thu, 5 Oct 2023 11:11:59 +0300 Subject: [PATCH] Add also peers --- templates/wireguard_client.conf | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/templates/wireguard_client.conf b/templates/wireguard_client.conf index 1ceb35e..d07166f 100644 --- a/templates/wireguard_client.conf +++ b/templates/wireguard_client.conf @@ -4,11 +4,24 @@ PrivateKey = {{ private_key }} ListenPort = {{ listenport }} {% if vpn_dns is defined %}DNS = {{ vpn_dns }}{% endif %} +# From inventory {% for item in groups['wireguard_clients'] %}{% if hostvars[item]['inventory_hostname'] != inventory_hostname and 'PublicKey' in hostvars[item] and 'AllowedIPs' in hostvars[item] %} - # Peer name: {{ item }} [Peer] PublicKey = {{ hostvars[item]['PublicKey'] }} AllowedIPs = {{ hostvars[item]['AllowedIPs'] }} {% if hostvars[item]['EndPointIP'] is defined and hostvars[item]['EndPointIP'] != '' %}EndPoint = {{ hostvars[item]['EndPointIP'] }}:{{ hostvars[item]['listenport'] | default(listenport) }} {% endif %}{% endif %}{% endfor %} + +# From peers configuration +{% for item in wireguard_peers %}{% if item['name'] != inventory_hostname and 'PublicKey' in item and 'AllowedIPs' in item %} + +# Peer name: {{ item.name }} +[Peer] +PublicKey = {{ item.PublicKey }} +AllowedIPs = {{ item.AllowedIPs }} +{% if item.EndPointIP is defined and item.EndPointIP != '' %} +EndPoint = {{ item.EndPointIP }}:{{ listenport }} +{% endif %} +{% endif %}{% endfor %} +