From 708a29ed99731c4658d1b627b5c2477bc1d9a1c7 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Fri, 4 Nov 2022 17:55:00 +0200 Subject: [PATCH] Use list of all peers --- tasks/configure.yml | 7 ++++--- templates/wireguard_client.conf | 14 +++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/tasks/configure.yml b/tasks/configure.yml index 1b02fb8..6ce1f95 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -7,8 +7,9 @@ - Restart Wireguard service - name: Register private key - shell: cat /etc/wireguard/privatekey - register: privatekey + slurp: + src: /etc/wireguard/privatekey + register: private_key - name: Ensure Wireguard client is configure template: @@ -35,4 +36,4 @@ name: Ping VPN server job: ping -c 3 192.168.2.1 &> /dev/null hour: '1' - user: gestor \ No newline at end of file + user: gestor diff --git a/templates/wireguard_client.conf b/templates/wireguard_client.conf index 7907677..a0de8a7 100644 --- a/templates/wireguard_client.conf +++ b/templates/wireguard_client.conf @@ -1,10 +1,14 @@ [Interface] Address = {{ addresses[ansible_hostname] }} -PrivateKey = {{ privatekey.stdout }} +PrivateKey = {{ private_key }} ListenPort = {{ listenport }} -# Server: +{% for item in wireguard_peers %} + +# Peer name: {{ item.name }} [Peer] -PublicKey = {{ server_publickey }} -AllowedIPs = {{ allowed_ips }} -EndPoint = {{ endpoint }} \ No newline at end of file +PublicKey = {{ item.PublicKey }} +AllowedIPs = {{ item.AllowedIPs }} +{% if item.EndPointIP is defined and item.EndPointIP != '' %} +EndPoint = {{ item.EndPointIP }}:{{ listenport }} +{% endfor %}