Tyler-OBrien / wireguard-mesh-network-ansible

Automatically create and set up a wireguard mesh network using Ansible
4 stars 4 forks source link

Can't add new host to existing mesh network #1

Open bluepuma77 opened 9 months ago

bluepuma77 commented 9 months ago

First of all thanks for the template! 🙂

Currently testing, it seems to throw an error when trying to add a new host to an existing mesh, so when running the playback again on the old hosts:

TASK [Use wg-quick to setup] **********************************************************************************************************************************************************
fatal: [db1]: FAILED! => {"changed": true, "cmd": ["wg-quick", "up", "wg0"], "delta": "0:00:00.013099", "end": "2024-02-12 20:15:16.900936", "msg": "non-zero return code", "rc": 1, "start": "2024-02-12 20:15:16.887837", "stderr": "wg-quick: `wg0' already exists", "stderr_lines": ["wg-quick: `wg0' already exists"], "stdout": "", "stdout_lines": []}

Any ideas how this could be circumvented? Some AI suggests do bring wg0 down first, but maybe a reload would keep the whole mesh and ongoing traffic more stable?

PS: It seems the wireguard_mask_bits from inventory is never used.

Tyler-OBrien commented 9 months ago

Hey!

I changed out the bottom 2 commands to this once I get the mesh setup:

    - name: Use wg-quick to setup
      command: "wg-quick up wg0"
      become: yes
      ignore_errors: yes 

    - name: Enable wg-quick setup service
      command: "systemctl enable wg-quick@wg0.service"
      become: yes

    - name: restart if existing
      command: "systemctl restart wg-quick@wg0.service"
      become: yes
      ignore_errors: yes 

It's kind of hacky and silly but it works. My understanding is reload wouldn't bring in any new config, just from my limited testing. Restarting does cause latency to spike for a second. I use this mesh with a more immutable set of nodes which I change infrequently. My primary desire was to get something that doesn't depend on a third party. I use Tailscale/headscale for a more generic private network, which would work better if you are constantly adding/removing nodes. You can run wireguard mesh and tailscale together as well, to have two overlay networks of different node types, works well.