3
0
Fork 0

Compare commits

...

21 Commits

Author SHA1 Message Date
KemoNine 53efc122e3 Add note about fork 2020-08-04 22:01:34 +00:00
KemoNine 0217d41830 Add s6-svc restart for containers 2020-08-04 20:26:38 +00:00
KemoNine ef8de286b1 Started work on s6-svc restart of wireguard for containerized deployment(s) 2020-08-04 19:27:15 +00:00
KemoNine fbc79beb72 remove unnecessary whitespace from wg.conf template 2020-08-04 19:26:58 +00:00
KemoNine d1ed058fa8 Tweak default variable 2020-08-04 18:42:30 +00:00
KemoNine d00bcb7d6a Add missing default variable 2020-08-04 18:37:51 +00:00
KemoNine 0afb85375e Add containerization skips 2020-08-04 17:49:30 +00:00
KemoNine 1faf8d9f12 Attempt to tweak config generator to include ALL hosts that could have been included in the play, rather than just the ones matching filters (helpful for controller deployments) 2020-08-04 17:39:33 +00:00
KemoNine 8fc7870c76 Tweak wireguard role to ensure the bare-metal tasks can be skipped 2020-08-04 06:37:03 +00:00
Robert Wimmer d5b81cb75e
update CHANGELOG (#57)
Co-authored-by: githubixx <home@tauceti.net>
2020-06-14 17:56:46 +02:00
pallinger 1997b9d710
Fix on debian openstack images (#55)
* on openstack Debian images, the kernel is different, so we need to install different kernel headers, too

* fix syntax error in conditional fact

* remove debug message

Co-authored-by: Peter Pallinger <pallinger@sztaki.hu>
2020-06-14 17:52:17 +02:00
Robert Wimmer 359d601008
update CHANGELOG for version 6.3.0 (#56)
Co-authored-by: githubixx <home@tauceti.net>
2020-06-04 23:22:47 +02:00
Stefan Haun 2ef11ac648
Add a role for Raspbian (#54)
* Rename debian-setup role to point to vanilla Debian

* Add a specific setup role for Raspbian

This role will fail for now, Raspbian is not supported by this role as it is.

* Add a switch for Raspbian

* Add Raspbian role for installing WireGuard

* Raspbian: Handle reboot with molly-guard and older Ansible versions
2020-06-04 23:17:25 +02:00
Robert Wimmer 9f76b8baf5
Support Ubuntu 20.04 (#52)
* update Ansible Galaxy meta info (added Ubunut Focal Fossa / Debian Buster)

* update CHANGELOG (Ubuntu 20.04 support)

* move OS package installation to OS specific subtasks

* update README

* update CHANGELOG

Co-authored-by: githubixx <home@tauceti.net>
2020-05-04 23:27:56 +02:00
Robert Wimmer 97f566ad85
cleanup (#51)
* update CHANGELOG

* fix typo

* update CHANGELOG

Co-authored-by: githubixx <home@tauceti.net>
2020-05-02 21:32:09 +02:00
Jürgen Hötzel 04843b5394
Use Arch Linux specific package list (#48)
Arch Linux ships a Linux kernel > 5.6 and doesn't require DKMS.

Move the package list variable to (distribution-specific) var files.

For the Arch Linux LTS kernel (5.4) a binary wireguard-lts package is
provided in [core].
2020-05-02 21:12:34 +02:00
Ties de Kock 13621d4d68
Use wireguard from buster-backports on debian if needed (#49)
* Changes wireguard apt repo to buster-backports

* Add repo only on buster or earlier

* No apt pin needed, backports has lower priority than main distribution

* Update CHANGELOG.md

Co-Authored-By: Robert Wimmer <2039811+githubixx@users.noreply.github.com>

* Clarify effects of updating on system state

Co-authored-by: Robert Wimmer <2039811+githubixx@users.noreply.github.com>
2020-04-28 21:01:46 +02:00
Robert Wimmer 9be9694553
update README (version 6.0.3) (#47)
Co-authored-by: githubixx <home@tauceti.net>
2020-04-03 21:03:23 +02:00
Cristian Chiru 6348c48193
Forcing stop and start to clear routes (#46) 2020-04-03 20:59:32 +02:00
Robert Wimmer 43ad9a1cfe
add changes for version 6.0.2 (#44)
Co-authored-by: githubixx <home@tauceti.net>
2020-03-18 20:18:02 +01:00
James Kiefer a7ada33e73
Bugfix: Install gnupg instead of gpg for debian (#43) 2020-03-18 20:12:19 +01:00
15 changed files with 343 additions and 124 deletions

View File

@ -1,6 +1,47 @@
Changelog
---------
**6.3.1**
- Support Openstack Debian images (contribution by @pallinger)
**6.3.0**
- Support Raspbian (contribution by @penguineer)
**6.2.0**
- Support Ubuntu 20.04 (Focal Fossa)
- Introduce `wireguard_ubuntu_update_cache` and `wireguard_ubuntu_cache_valid_time` variables to specifiy individual Ubuntu package cache settings. Default values are the same as before.
- As kernel >= 5.6 (and kernel 5.4 in Ubuntu 20.04) now have `wireguard` module included `wireguard-dkms` package is no longer needed in that case. That's why WireGuard package installation is now part of the includes for the specific OS to make it easier to handle various cases.
**6.1.0**
- Archlinux: Linux kernel >= 5.6 contains `wireguard` module now. No need to install `wireguard-dkms` anymore in this case. Installations with LTS kernel installs `wireguard-lts` package now instead of `wireguard-dkms`. Installations with kernel <= 5.6 will still install `wireguard-dkms` package.
**6.0.4**
- Use the buster-backports repository on Debian Buster (or older), use package standard repositories on sid/bullseye.
standard repositories on sid/bullseye.
The role no longer adds the unstable _repo_ nor the _apt preference_ for that repo. There is no need to clean the preference and unstable repository, since packages from your release have a higher priority.
If you remove the apt preference (`/etc/apt/preferences.d/limit-unstable`) updates from `unstable` are accepted by apt. This likely is not what you want and may lead to an unstable state.
If you want to clean up:
* remove `/etc/apt/preferences.d/limit-unstable` and
* remove `deb http://deb.debian.org/debian/ unstable main` from `/etc/apt/sources.list.d/deb_debian_org_debian.list`.
The backports repository has a lower priority and does not need an apt preference.
**6.0.3**
- If `wg syncconf` command is not available do stop/start service instead of restart (contribution by @cristichiru)
**6.0.2**
- Debian: install `gnupg` package instead of `gpg`. (contribution by @zinefer)
**6.0.1**
- add shell options to syncconf handler to fail fast in case of error

View File

@ -1,3 +1,5 @@
# Fork of https://github.com/githubixx/ansible-role-wireguard.git with some minor tweaks to ensure PiFrameFleet can be provisioned properly
ansible-role-wireguard
======================
@ -7,7 +9,7 @@ I used [PeerVPN](https://peervpn.net/) before but that wasn't updated for a whil
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/).
This role was tested with Ubuntu 18.04 (Bionic Beaver), Debian 9 (Stretch), Archlinux, Fedora 31 and CentOS. It might also work with Ubuntu 16.04 (Xenial Xerus), Debian 10 (Buster) or other distributions but haven't tested it. If someone tested it let me please know if it works or send a pull request to make it work ;-)
This role is tested with Ubuntu 18.04 (Bionic Beaver), Ubuntu 20 (Focal Fossa) and Archlinux. Ubuntu 16.04 (Xenial Xerus), Debian 9 (Stretch), Debian 10 (Buster), Fedora 31 (or later) and CentOS 7 might also work or other distributions but haven't tested it (code for this operating systems was submitted by other contributors). If someone tested it let me please know if it works or send a pull request to make it work ;-)
Versions
--------
@ -294,11 +296,13 @@ vpn1:
vpn2:
hosts:
# use a different name, and define ansible_host, to avoid mixing of vars without needing to prefix vars with interface name
# Use a different name, and define ansible_host, to avoid mixing of vars without
# needing to prefix vars with interface name.
multi-wg1:
ansible_host: multi
wireguard_interface: wg1
wireguard_port: 51821 # when using several interface on one host, we must use different ports
# when using several interface on one host, we must use different ports
wireguard_port: 51821
wireguard_address: 10.9.1.1/32
wireguard_endpoint: multi.exemple.com
another:

View File

@ -1,4 +1,8 @@
---
#######################################
# General settings
#######################################
# Directory to store WireGuard configuration on the remote hosts
wireguard_remote_directory: "/etc/wireguard"
@ -7,3 +11,17 @@ wireguard_port: "51820"
# The default interface name that wireguard should use if not specified otherwise.
wireguard_interface: "wg0"
# Whether or not WireGuard is running in a container
wireguard_containerized: false
#######################################
# Settings only relevant for Ubuntu
#######################################
# Set to "false" if package cache should not be updated
wireguard_ubuntu_update_cache: "true"
# Set package cache valid time
wireguard_ubuntu_cache_valid_time: "3600"

View File

@ -1,3 +0,0 @@
Package: *
Pin: release a=unstable
Pin-Priority: 90

View File

@ -2,8 +2,11 @@
- name: restart wireguard
service:
name: "wg-quick@{{ wireguard_interface }}"
state: restarted
when: not wg_syncconf
state: "{{ item }}"
loop:
- stopped
- started
when: not wg_syncconf and not wireguard_containerized
listen: "reconfigure wireguard"
- name: syncconf wireguard
@ -16,5 +19,10 @@
exit 0
args:
executable: "/bin/bash"
when: wg_syncconf
when: wg_syncconf and not wireguard_containerized
listen: "reconfigure wireguard"
- name: restart wireguard (container)
command: /usr/bin/s6-svc -r /var/run/s6/services/wireguard
when: wireguard_containerized
listen: "reconfigure wireguard"

View File

@ -8,9 +8,11 @@ galaxy_info:
- name: Ubuntu
versions:
- bionic
- focal
- name: Debian
versions:
- stretch
- buster
- name: EL
versions:
- 7

View File

@ -3,17 +3,7 @@
setup:
- include_tasks: "setup-{{ ansible_distribution|lower }}.yml"
- name: Install WireGuard
package:
name: "{{ packages }}"
state: present
vars:
packages:
- wireguard-dkms
- wireguard-tools
tags:
- wg-install
when: not wireguard_containerized
- name: Enable WireGuard kernel module
modprobe:
@ -42,6 +32,7 @@
- name: Get wg subcommands
command: "wg --help"
register: wg_subcommands
changed_when: false
- name: Set default value for wg_syncconf variable (assume wg syncconf subcommand not available)
set_fact:
@ -58,8 +49,9 @@
- block:
- name: Generate WireGuard private key
shell: "wg genkey"
command: "wg genkey"
register: wg_private_key_result
changed_when: false
tags:
- wg-generate-keys
@ -138,3 +130,4 @@
name: "wg-quick@{{ wireguard_interface }}"
state: started
enabled: yes
when: not wireguard_containerized

View File

@ -1,11 +1,32 @@
---
- name: Install required packages
- name: (Archlinux) Install wireguard-lts package
pacman:
name: "{{ packages }}"
state: present
name: "{{ item.name }}"
state: "{{ item.state }}"
with_items:
- { name: wireguard-dkms, state: absent }
- { name: wireguard-lts, state: present }
become: yes
vars:
packages:
- linux-headers
tags:
- wg-install
when:
- ansible_kernel is match(".*-lts$")
- ansible_kernel is version('5.6', '<')
- name: (Archlinux) Install wireguard-dkms package
pacman:
name: wireguard-dkms
state: present
become: yes
tags:
- wg-install
when:
- not ansible_kernel is match(".*-lts$")
- ansible_kernel is version('5.6', '<')
- name: (Archlinux) Install wireguard-tools package
pacman:
name: wireguard-tools
state: present
tags:
- wg-install

View File

@ -1,11 +1,19 @@
---
- name: Add WireGuard repository
- name: (CentOS) Add WireGuard repository
get_url:
url: https://copr.fedorainfracloud.org/coprs/jdoss/wireguard/repo/epel-7/jdoss-wireguard-epel-7.repo
dest: /etc/yum.repos.d/wireguard.repo
- name: Install EPEL repository
- name: (CentOS) Install EPEL repository
yum:
name: epel-release
update_cache: yes
- name: (CentOS) Install wireguard packages
yum:
name:
- "wireguard-dkms"
- "wireguard-tools"
state: present
tags:
- wg-install

View File

@ -0,0 +1,93 @@
---
- name: (Raspbian) Install GPG - required to add wireguard key
apt:
name: gnupg
state: present
- name: (Raspbian) Add Debian repository key
apt_key:
keyserver: "keyserver.ubuntu.com"
id: "04EE7237B7D453EC"
state: present
when: ansible_lsb.id == "Raspbian"
tags:
- wg-install
- name: (Raspbian) Add Debian Unstable repository for WireGuard
apt_repository:
repo: "deb http://deb.debian.org/debian unstable main"
state: present
update_cache: yes
tags:
- wg-install
- name: (Raspbian) Install latest kernel
apt:
name:
- "raspberrypi-kernel"
state: latest
register: kernel_update
tags:
- wg-install
- name: (Raspbian) Reboot after kernel update (Ansible >= 2.8)
reboot:
search_paths: ['/lib/molly-guard', '/usr/sbin']
when:
- ansible_version.full is version('2.8.0', '>=')
- kernel_update is changed
tags:
- wg-install
- name: (Raspbian) Check if molly-guard is installed (Ansible < 2.8)
stat:
path: /lib/molly-guard/
register: molly_guard
- name: (Raspbian) Reboot after kernel update (Ansible < 2.8, no molly-guard)
reboot:
when:
- ansible_version.full is version('2.8.0', '<')
- kernel_update is changed
- not molly_guard.stat.exists
tags:
- wg-install
- name: (Raspbian) Reboot after kernel update (Ansible < 2.8, with molly-guard)
command: /lib/molly-guard/shutdown -r now
async: 1
poll: 0
ignore_unreachable: yes
when:
- ansible_version.full is version('2.8.0', '<')
- kernel_update is changed
- molly_guard.stat.exists
tags:
- wg-install
- name: (Raspbian) Waiting for host to be available (Ansible < 2.8, with molly-guard)
wait_for_connection:
when:
- ansible_version.full is version('2.8.0', '<')
- kernel_update is changed
- molly_guard.stat.exists
tags:
- wg-install
- name: (Raspbian) Install latest kernel headers to compile Wireguard with DKMS
apt:
name:
- "raspberrypi-kernel-headers"
state: latest
tags:
- wg-install
- name: (Raspbian) Install wireguard packages
apt:
name:
- "wireguard-dkms"
- "wireguard-tools"
state: present
tags:
- wg-install

View File

@ -0,0 +1,37 @@
---
- name: (Debian) Install GPG - required to add wireguard key
apt:
name: gnupg
state: present
- name: (Debian) Add WireGuard repository on buster or earlier
apt_repository:
repo: "deb http://deb.debian.org/debian buster-backports main"
state: present
update_cache: yes
when: ansible_distribution_version | int <= 10
tags:
- wg-install
- name: (Debian) Get architecture
command: "dpkg --print-architecture"
register: dpkg_arch
changed_when: False
- set_fact:
kernel_header_version: "{{ ('-cloud-' in ansible_kernel) | ternary(ansible_kernel,dpkg_arch.stdout) }}"
- name: (Debian) Install kernel headers to compile Wireguard with DKMS
apt:
name:
- "linux-headers-{{ kernel_header_version }}"
state: present
- name: (Debian) Install wireguard packages
apt:
name:
- "wireguard-dkms"
- "wireguard-tools"
state: present
tags:
- wg-install

View File

@ -1,42 +1,8 @@
---
- name: Setup WireGuard preference
copy:
src: debian/etc/apt/preferences.d/limit-unstable
dest: /etc/apt/preferences.d/limit-unstable
owner: root
group: root
mode: 0644
tags:
- wg-install
- name: Install GPG - required to add wireguard key
apt:
name: gpg
state: present
- include_tasks: "setup-debian-raspbian.yml"
when: ansible_lsb.id == "Raspbian"
register: raspbian_setup
- name: Add WireGuard key
apt_key:
keyserver: "keyserver.ubuntu.com"
id: "8B48AD6246925553"
state: present
tags:
- wg-install
- name: Add WireGuard repository
apt_repository:
repo: "deb http://deb.debian.org/debian/ unstable main"
state: present
update_cache: yes
tags:
- wg-install
- name: Get architecture
shell: dpkg --print-architecture
register: dpkg_arch
changed_when: False
- name: Install kernel headers to compile wireguard with DKMS
apt:
name:
- "linux-headers-{{ dpkg_arch.stdout }}"
state: present
- include_tasks: "setup-debian-vanilla.yml"
when: raspbian_setup is skipped

View File

@ -1,8 +1,17 @@
---
- name: Add wireguard COPR
yum_repository:
name: "jdoss-wireguard"
description: "Copr repo for wireguard owned by jdoss"
baseurl: "https://copr-be.cloud.fedoraproject.org/results/jdoss/wireguard/fedora-$releasever-$basearch/"
gpgkey: "https://copr-be.cloud.fedoraproject.org/results/jdoss/wireguard/pubkey.gpg"
gpgcheck: yes
- name: (Fedora) Add wireguard COPR
yum_repository:
name: "jdoss-wireguard"
description: "Copr repo for wireguard owned by jdoss"
baseurl: "https://copr-be.cloud.fedoraproject.org/results/jdoss/wireguard/fedora-$releasever-$basearch/"
gpgkey: "https://copr-be.cloud.fedoraproject.org/results/jdoss/wireguard/pubkey.gpg"
gpgcheck: yes
- name: (Fedora) Install wireguard packages
yum:
name:
- "wireguard-dkms"
- "wireguard-tools"
state: present
tags:
- wg-install

View File

@ -1,26 +1,48 @@
---
- name: Update APT package cache
- name: (Ubuntu) Update APT package cache
apt:
update_cache: true
cache_valid_time: 3600
update_cache: "{{ wireguard_ubuntu_update_cache }}"
cache_valid_time: "{{ wireguard_ubuntu_cache_valid_time }}"
tags:
- wg-install
- name: Install required packages
package:
name: "{{ packages }}"
state: present
vars:
packages:
- software-properties-common
- linux-headers-{{ ansible_kernel }}
tags:
- wg-install
- block:
- name: (Ubuntu) Install support packages needed for Wireguard (for Ubuntu < 19.10)
package:
name: "{{ packages }}"
state: present
vars:
packages:
- software-properties-common
- linux-headers-{{ ansible_kernel }}
tags:
- wg-install
- name: Add WireGuard repository
apt_repository:
repo: "ppa:wireguard/wireguard"
state: present
update_cache: yes
tags:
- wg-install
- name: (Ubuntu) Add WireGuard repository (for Ubuntu < 19.10)
apt_repository:
repo: "ppa:wireguard/wireguard"
state: present
update_cache: yes
tags:
- wg-install
- name: (Ubuntu) Install wireguard packages (for Ubuntu < 19.10)
apt:
name:
- "wireguard-dkms"
- "wireguard-tools"
state: present
tags:
- wg-install
when:
- ansible_lsb.major_release is version('19.10', '<')
- block:
- name: (Ubuntu) Install wireguard-tools package (for Ubuntu > 19.04)
apt:
name: "wireguard-tools"
state: present
tags:
- wg-install
when:
- ansible_lsb.major_release is version('19.04', '>')

View File

@ -39,32 +39,32 @@ PostDown = {{ wg_postdown }}
{% if hostvars[inventory_hostname].wireguard_save_config is defined %}
SaveConfig = true
{% endif %}
{% for host in ansible_play_hosts %}
{% if host != inventory_hostname %}
[Peer]
# {{ host }}
PublicKey = {{hostvars[host].public_key}}
{% if hostvars[host].wireguard_allowed_ips is defined %}
AllowedIPs = {{hostvars[host].wireguard_allowed_ips}}
{% else %}
AllowedIPs = {{hostvars[host].wireguard_ip}}/32
{% endif %}
{% if hostvars[host].wireguard_persistent_keepalive is defined %}
PersistentKeepalive = {{hostvars[host].wireguard_persistent_keepalive}}
{% endif %}
{% if hostvars[host].wireguard_port is defined and hostvars[host].wireguard_port is number %}
{% if hostvars[host].wireguard_endpoint is defined and hostvars[host].wireguard_endpoint != "" %}
Endpoint = {{hostvars[host].wireguard_endpoint}}:{{hostvars[host].wireguard_port}}
{% else %}
Endpoint = {{host}}:{{hostvars[host].wireguard_port}}
{% endif %}
{% elif hostvars[host].wireguard_endpoint is defined and hostvars[host].wireguard_endpoint != "" %}
Endpoint = {{hostvars[host].wireguard_endpoint}}:{{wireguard_port}}
{% elif hostvars[host].wireguard_endpoint == "" %}
# No endpoint defined for this peer
{% else %}
Endpoint = {{host}}:{{wireguard_port}}
{% endif %}
{% endif %}
{% for host in ansible_play_hosts_all %}
{% if host != inventory_hostname %}
[Peer]
# {{ host }}
PublicKey = {{hostvars[host].public_key}}
{% if hostvars[host].wireguard_allowed_ips is defined %}
AllowedIPs = {{hostvars[host].wireguard_allowed_ips}}
{% else %}
AllowedIPs = {{hostvars[host].wireguard_ip}}/32
{% endif %}
{% if hostvars[host].wireguard_persistent_keepalive is defined %}
PersistentKeepalive = {{hostvars[host].wireguard_persistent_keepalive}}
{% endif %}
{% if hostvars[host].wireguard_port is defined and hostvars[host].wireguard_port is number %}
{% if hostvars[host].wireguard_endpoint is defined and hostvars[host].wireguard_endpoint != "" %}
Endpoint = {{hostvars[host].wireguard_endpoint}}:{{hostvars[host].wireguard_port}}
{% else %}
Endpoint = {{host}}:{{hostvars[host].wireguard_port}}
{% endif %}
{% elif hostvars[host].wireguard_endpoint is defined and hostvars[host].wireguard_endpoint != "" %}
Endpoint = {{hostvars[host].wireguard_endpoint}}:{{wireguard_port}}
{% elif hostvars[host].wireguard_endpoint == "" %}
# No endpoint defined for this peer
{% else %}
Endpoint = {{host}}:{{wireguard_port}}
{% endif %}
{% endif %}
{% endfor %}