githubixx / ansible-role-wireguard

Ansible role for installing WireGuard VPN. Supports Ubuntu, Debian, Archlinx, Fedora and CentOS.
https://www.tauceti.blog/post/kubernetes-the-not-so-hard-way-with-ansible-wireguard/
581 stars 181 forks source link

Add support for wireguard_include_peers variable #196

Open jelmer opened 12 months ago

jelmer commented 12 months ago

This allows explicitly setting which peers a node can connect to. If the variable is not present, then all peers are included.

Fixes #195

jelmer commented 11 months ago

That seems reasonable - updated to address your feedback.

jelmer commented 9 months ago

@githubixx any more thoughts on this?

githubixx commented 9 months ago

@jelmer Sorry, I'm currently a little bit short on time. I'll get back to you next week. I need to test the patch first to make sure it has no side effects. But it'd be helpful if you could extend the Molecule test accordingly. You don't have to execute it. It's just for me to have a starting point. Maybe make a copy of the Ubuntu 22.04 host and put it here with adjusted values. And the add the needed variable at the end here. Thanks!

jelmer commented 5 days ago

updated to resolve conflicts; I hope to get to adding tests sometime this month

kbcz1989 commented 5 days ago

@jelmer Hello. Thanks for getting back at this. I am in dire need of this change :) I wanted to make tests to get this going so Ill paste my change here, if it helps you anyhow:

-    - name: There should be as much WireGuard interfaces as hosts in vpn group minus one
+    - name: There should be as many WireGuard interfaces as hosts in vpn group minus one or as defined peers
       ansible.builtin.assert:
         that:
-          - "hosts_count|int -1 == wireguard__interfaces_count.stdout|int"
+          - >
+            (wireguard_include_peers is defined and
+             wireguard__interfaces_count.stdout|int == wireguard_include_peers|length) or
+            (wireguard_include_peers is not defined and
+             hosts_count|int - 1 == wireguard__interfaces_count.stdout|int)