Add basic support for macOS (#61)

Add macOS details in the README

Fix Archlinux spelling

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

Remove additional linux.yml file, use conditional block instead

Add CHANGELOG entry

Bump to 7.2.0 in CHANGELOG

Invert OS check on Darwin instead of Linux
Co-authored-by: Robert Wimmer <2039811+githubixx@users.noreply.github.com>

Co-authored-by: Robert Wimmer <2039811+githubixx@users.noreply.github.com>
master
Ruben Di Battista 4 years ago committed by GitHub
parent e9e95f80e0
commit 3ef759edbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,5 +1,8 @@
Changelog Changelog
--------- ---------
**7.2.0**
- Basic MacOS X support (contribution by @rubendibattista)
**7.1.0** **7.1.0**

@ -9,6 +9,22 @@ In general WireGuard is a network tunnel (VPN) for IPv4 and IPv6 that uses UDP.
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 ;-) 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 ;-)
### Running the VPN on 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:
```
sudo wg-quick up wg0
```
and to deactivate it
```
sudo wg-quick down wg0
```
or you can install the [official app](https://apps.apple.com/it/app/wireguard/id1451685025?l=en&mt=12) and import the `wg0.conf` file.
Versions Versions
-------- --------
@ -31,7 +47,8 @@ These variables can be changed in `group_vars/`:
```yaml ```yaml
# Directory to store WireGuard configuration on the remote hosts # Directory to store WireGuard configuration on the remote hosts
wireguard_remote_directory: "/etc/wireguard" wireguard_remote_directory: "/etc/wireguard" # On Linux
# wireguard_remote_directory: "/opt/local/etc/wireguard" # On macOS
# The default port WireGuard will listen if not specified otherwise. # The default port WireGuard will listen if not specified otherwise.
wireguard_port: "51820" wireguard_port: "51820"

@ -4,7 +4,7 @@
####################################### #######################################
# Directory to store WireGuard configuration on the remote hosts # Directory to store WireGuard configuration on the remote hosts
wireguard_remote_directory: "/etc/wireguard" wireguard_remote_directory: "{{ '/etc/wireguard' if not ansible_os_family == 'Darwin' else '/opt/local/etc/wireguard' }}"
# The default port WireGuard will listen if not specified otherwise. # The default port WireGuard will listen if not specified otherwise.
wireguard_port: "51820" wireguard_port: "51820"
@ -12,6 +12,15 @@ wireguard_port: "51820"
# The default interface name that wireguard should use if not specified otherwise. # The default interface name that wireguard should use if not specified otherwise.
wireguard_interface: "wg0" wireguard_interface: "wg0"
# The default owner of the wg.conf file
wireguard_conf_owner: root
# The default group of the wg.conf file
wireguard_conf_group: "{{ 'root' if not ansible_os_family == 'Darwin' else 'wheel' }}"
# The default mode of the wg.conf file
wireguard_conf_mode: 0600
####################################### #######################################
# Settings only relevant for Ubuntu # Settings only relevant for Ubuntu

@ -6,7 +6,9 @@
loop: loop:
- stopped - stopped
- started - started
when: not wg_syncconf when: >
not wg_syncconf and
not ansible_os_family == 'Darwin'
listen: "reconfigure wireguard" listen: "reconfigure wireguard"
- name: syncconf wireguard - name: syncconf wireguard
@ -19,5 +21,7 @@
exit 0 exit 0
args: args:
executable: "/bin/bash" executable: "/bin/bash"
when: wg_syncconf when: >
wg_syncconf and
not ansible_os_family == 'Darwin'
listen: "reconfigure wireguard" listen: "reconfigure wireguard"

@ -10,7 +10,8 @@
- "setup-{{ ansible_distribution|lower }}.yml" - "setup-{{ ansible_distribution|lower }}.yml"
- "setup-{{ ansible_os_family|lower }}.yml" - "setup-{{ ansible_os_family|lower }}.yml"
- name: Enable WireGuard kernel module - block:
- name: Enable WireGuard kernel module
modprobe: modprobe:
name: wireguard name: wireguard
state: present state: present
@ -21,6 +22,7 @@
failed_when: wireguard_module_enabled is failure failed_when: wireguard_module_enabled is failure
tags: tags:
- wg-install - wg-install
when: not ansible_os_family == 'Darwin'
- name: Set WireGuard IP (without mask) - name: Set WireGuard IP (without mask)
set_fact: set_fact:
@ -107,9 +109,9 @@
template: template:
src: wg.conf.j2 src: wg.conf.j2
dest: "{{ wireguard_remote_directory }}/{{ wireguard_interface }}.conf" dest: "{{ wireguard_remote_directory }}/{{ wireguard_interface }}.conf"
owner: root owner: "{{ wireguard_conf_owner }}"
group: root group: "{{ wireguard_conf_group }}"
mode: 0600 mode: "{{ wireguard_conf_mode }}"
tags: tags:
- wg-config - wg-config
notify: notify:
@ -135,3 +137,4 @@
name: "wg-quick@{{ wireguard_interface }}" name: "wg-quick@{{ wireguard_interface }}"
state: started state: started
enabled: yes enabled: yes
when: not ansible_os_family == 'Darwin'

@ -0,0 +1,15 @@
---
- name: (MacOS) Install wireguard package
package:
name: wireguard-go
state: present
become: yes
tags:
- wg-install
- name: (MacOS) Install wireguard-tools package
package:
name: wireguard-tools
state: present
tags:
- wg-install
Loading…
Cancel
Save