Skip to content

Commit

Permalink
Prep for 17.1.0 (#212)
Browse files Browse the repository at this point in the history
* remove whitespace

* update .yamllint

* ansible-lint: Fix forbidden implicit octal value

* use ansible.builtin.dnf instead of ansible.builtin.yum for Fedora

* update .gitignore

* add missing wg-config tag

* hide peers with empty endpoints for unmanaged peers

* Revert "hide peers with empty endpoints for unmanaged peers"

This reverts commit 85818e1.

* update README

* update dates
  • Loading branch information
githubixx authored Nov 6, 2024
1 parent 955e64b commit 594dcaf
Show file tree
Hide file tree
Showing 34 changed files with 62 additions and 49 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (C) 2018-2023 Robert Wimmer
# Copyright (C) 2018-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

molecule/kvm/.vagrant
.vscode
11 changes: 10 additions & 1 deletion .yamllint
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
---
# Copyright (C) 2018-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later
extends: default

rules:
line-length:
max: 150
level: warning

comments-indentation: disable
comments:
min-spaces-from-content: 1
braces:
min-spaces-inside: 0
max-spaces-inside: 1
octal-values:
forbid-implicit-octal: true
forbid-explicit-octal: true
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
- replace Vagrant box `rockylinux/9` with `bento/rockylinux-9`
- use `ansible.builtin.package` for AlmaLinux
- remove `AlmaLinux 8`, `Rocky Linux 8` and `CentOS 7` (outdated Python makes it hard to test with Ansible)

## 16.0.2

- **OTHER**
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (C) 2018-2023 Robert Wimmer
Copyright (C) 2018-2024 Robert Wimmer
Copyright (C) 2019 fbourqui
SPDX-License-Identifier: GPL-3.0-or-later
-->
Expand All @@ -10,7 +10,9 @@ This Ansible role is used in my blog series [Kubernetes the not so hard way with

In general WireGuard is a network tunnel (VPN) for IPv4 and IPv6 that uses UDP. If you need more information about [WireGuard](https://www.wireguard.io/) you can find a good introduction here: [Installing WireGuard, the Modern VPN](https://research.kudelskisecurity.com/2017/06/07/installing-wireguard-the-modern-vpn/).

## Linux
## Supported operating systems

### Linux

This role should work with:

Expand All @@ -27,16 +29,14 @@ This role should work with:
- openSUSE Leap 15.6
- Oracle Linux 9

## Best effort
### Linux - Best effort

- AlmaLinux 8
- Rocky Linux 8
- elementary OS 6
- CentOS 7 (end of life since end June 2024)

Molecule tests are [available](https://github.com/githubixx/ansible-role-wireguard#testing) (see further down below). It should also work with `Raspbian Buster` but for this one there is no test available. MacOS (see below) should also work partially but is only best effort.

## MacOS
### MacOS

While this playbook configures, enables and starts a `systemd` service on Linux in a such a way that no additional action is needed, on MacOS it installs the required packages and it just generates the correct `wg0.conf` file that is then placed in the specified `wireguard_remote_directory` (`/opt/local/etc/wireguard` by default). In order to run the VPN, then, you need to:

Expand Down Expand Up @@ -376,6 +376,8 @@ wireguard_unmanaged_peers:

One of `wireguard_address` (deprecated) or `wireguard_addresses` (recommended) is required as already mentioned. It's the IPs of the interface name defined with `wireguard_interface` variable (`wg0` by default). Every host needs at least one unique VPN IP of course. If you don't set `wireguard_endpoint` the playbook will use the hostname defined in the `vpn` hosts group (the Ansible inventory hostname). If you set `wireguard_endpoint` to `""` (empty string) that peer won't have a endpoint. That means that this host can only access hosts that have a `wireguard_endpoint`. That's useful for clients that don't expose any services to the VPN and only want to access services on other hosts. So if you only define one host with `wireguard_endpoint` set and all other hosts have `wireguard_endpoint` set to `""` (empty string) that basically means you've only clients besides one which in that case is the WireGuard server. The third possibility is to set `wireguard_endpoint` to some hostname. E.g. if you have different hostnames for the private and public DNS of that host and need different DNS entries for that case setting `wireguard_endpoint` becomes handy. Take for example the IP above: `wireguard_address: "10.8.0.101"`. That's a private IP and I've created a DNS entry for that private IP like `host01.i.domain.tld` (`i` for internal in that case). For the public IP I've created a DNS entry like `host01.p.domain.tld` (`p` for public). The `wireguard_endpoint` needs to be a interface that the other members in the `vpn` group can connect to. So in that case I would set `wireguard_endpoint` to `host01.p.domain.tld` because WireGuard normally needs to be able to connect to the public IP of the other host(s).

## Example

Here is a litte example for what I use the playbook: I use WireGuard to setup a fully meshed VPN (every host can directly connect to every other host) and run my Kubernetes (K8s) cluster at Hetzner Cloud (but you should be able to use any hoster you want). So the important components like the K8s controller and worker nodes (which includes the pods) only communicate via encrypted WireGuard VPN. Also (as already mentioned) I've two clients. Both have `kubectl` installed and are able to talk to the internal Kubernetes API server by using WireGuard VPN. One of the two clients also exposes a WireGuard endpoint because the Postfix mailserver in the cloud and my internal Postfix needs to be able to talk to each other. I guess that's maybe a not so common use case for WireGuard :D But it shows what's possible. So let me explain the setup which might help you to use this Ansible role.

First, here is a part of my Ansible `hosts` file:
Expand Down Expand Up @@ -585,7 +587,7 @@ vpn2:
- "10.9.1.1/32"
wireguard_endpoint: multi.example.com
another:
wireguard_address:
wireguard_addresses:
- "10.9.1.2/32"
wireguard_endpoint: another.example.com
```
Expand Down
4 changes: 2 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2018-2023 Robert Wimmer
# Copyright (C) 2018-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

#######################################
Expand Down Expand Up @@ -35,7 +35,7 @@ wireguard_conf_filename: "{{ wireguard_interface }}.conf"
wireguard_conf_group: "{{ 'root' if not ansible_os_family == 'Darwin' else 'wheel' }}"

# The default mode of the wg.conf file
wireguard_conf_mode: 0600
wireguard_conf_mode: "0600"

# Whether any change to the wg.conf file should be backup
wireguard_conf_backup: false
Expand Down
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2018-2023 Robert Wimmer
# Copyright (C) 2018-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Restart wireguard
Expand Down
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2018-2023 Robert Wimmer
# Copyright (C) 2018-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

galaxy_info:
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2020-2023 Robert Wimmer
# Copyright (C) 2020-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Setup WireGuard
Expand Down
4 changes: 2 additions & 2 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# Copyright (C) 2020-2023 Robert Wimmer
# Copyright (C) 2020 Pierre Ozoux
# Copyright (C) 2020-2024 Robert Wimmer
# Copyright (C) 2020-2024 Pierre Ozoux
# SPDX-License-Identifier: GPL-3.0-or-later

dependency:
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2021-2023 Robert Wimmer
# Copyright (C) 2021-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Prepare opensuse hosts
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2023 Robert Wimmer
# Copyright (C) 2023-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Verify setup
Expand Down
2 changes: 1 addition & 1 deletion molecule/single-server/converge.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2023 Robert Wimmer
# Copyright (C) 2023-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Setup WireGuard
Expand Down
2 changes: 1 addition & 1 deletion molecule/single-server/molecule.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2023 Robert Wimmer
# Copyright (C) 2023-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

dependency:
Expand Down
2 changes: 1 addition & 1 deletion molecule/single-server/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2023 Robert Wimmer
# Copyright (C) 2023-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Setup Ubuntu hosts
Expand Down
2 changes: 1 addition & 1 deletion molecule/single-server/verify.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2023 Robert Wimmer
# Copyright (C) 2023-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Verify setup
Expand Down
5 changes: 3 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2018-2023 Robert Wimmer
# Copyright (C) 2018-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Gather instance facts
Expand Down Expand Up @@ -45,6 +45,7 @@
false
{%- endif %}
tags:
- wg-config
- skip_ansible_lint

- name: Make sure wg syncconf option is available
Expand Down Expand Up @@ -160,7 +161,7 @@
ansible.builtin.file:
dest: "{{ wireguard_remote_directory }}"
state: directory
mode: 0700
mode: "0700"
tags:
- wg-config
when: not wireguard_ubuntu_use_netplan
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-almalinux-8.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2021-2023 Robert Wimmer
# Copyright (C) 2021-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (AlmaLinux 8) Install EPEL & ELRepo repository
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-almalinux.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2023 Robert Wimmer
# Copyright (C) 2023-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (AlmaLinux) Install wireguard-tools package
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-archlinux.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2018-2023 Robert Wimmer
# Copyright (C) 2018-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (Archlinux) Refresh the master package lists
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-centos-7.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2020 Roman Danko
# Copyright (C) 2020-2024 Roman Danko
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (CentOS 7) Tasks for standard kernel
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-debian-pve-guest-variant.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2021 Tobias Richter
# Copyright (C) 2021-2024 Tobias Richter
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (Proxmox) Add WireGuard repository
Expand Down
6 changes: 3 additions & 3 deletions tasks/setup-debian-pve-host-variant.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# Copyright (C) 2018-2023 Robert Wimmer
# Copyright (C) 2019-2020 Ties de Kock
# Copyright (C) 2021 Steve Fan
# Copyright (C) 2018-2024 Robert Wimmer
# Copyright (C) 2019-2024 Ties de Kock
# Copyright (C) 2021-2024 Steve Fan
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (Proxmox) Add WireGuard repository
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-debian-raspbian-buster.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2020 Stefan Haun
# Copyright (C) 2020-2024 Stefan Haun
# SPDX-License-Identifier: GPL-3.0-or-later

# Note: This setup is called for Raspbian 10 (Buster) and lower.
Expand Down
4 changes: 2 additions & 2 deletions tasks/setup-debian-vanilla.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# Copyright (C) 2018-2023 Robert Wimmer
# Copyright (C) 2019-2020 Ties de Kock
# Copyright (C) 2018-2024 Robert Wimmer
# Copyright (C) 2019-2024 Ties de Kock
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (Debian) Install WireGuard packages
Expand Down
4 changes: 2 additions & 2 deletions tasks/setup-debian.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# Copyright (C) 2020 Stefan Haun
# Copyright (C) 2021 Steve Fan
# Copyright (C) 2020-2024 Stefan Haun
# Copyright (C) 2021-2024 Steve Fan
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Setup for Raspbian
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-elementary os.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2023 Robert Wimmer
# Copyright (C) 2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (elementary OS) Update APT package cache
Expand Down
6 changes: 3 additions & 3 deletions tasks/setup-fedora.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
# Copyright (C) 2020 Ties de Kock
# Copyright (C) 2023 Robert Wimmer
# Copyright (C) 2020-2024 Ties de Kock
# Copyright (C) 2023-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (Fedora) Install WireGuard packages
when:
- ansible_pkg_mgr != "atomic_container"
ansible.builtin.yum:
ansible.builtin.dnf:
name:
- "wireguard-tools"
state: present
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-macosx.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2020 Ruben Di Battista
# Copyright (C) 2020-2024 Ruben Di Battista
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (MacOS) Install wireguard package
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-opensuse leap.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2020-2023 Robert Wimmer
# Copyright (C) 2020-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (openSUSE Leap) Install WireGuard packages
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-oraclelinux.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2022 Masahiro Koga
# Copyright (C) 2022-2024 Masahiro Koga
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (OracleLinux) Install wireguard-tools package
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-rocky-8.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2021-2023 Robert Wimmer
# Copyright (C) 2021-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (Rocky Linux 8) Tasks for standard kernel
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-rocky.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2023 Robert Wimmer
# Copyright (C) 2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: (Rocky Linux) Install wireguard-tools package
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# Copyright (C) 2018-2023 Robert Wimmer
# Copyright (C) 2018-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later

- name: Check if Netplan is supported
Expand Down
2 changes: 1 addition & 1 deletion templates/etc/wireguard/wg.conf.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#jinja2: lstrip_blocks:"True",trim_blocks:"True"
{# Copyright (C) 2018-2023 Robert Wimmer
{# Copyright (C) 2018-2024 Robert Wimmer
# SPDX-License-Identifier: GPL-3.0-or-later
#}
# {{ ansible_managed }}
Expand Down

0 comments on commit 594dcaf

Please sign in to comment.