Add wireguard_private_key variable (#69)
* Fix check mode for Debian * Add wireguard_private_key variable * Release 7.6.0 * Fix undefined `wg_syncconf` when using tags
This commit is contained in:
parent
65e94eaebb
commit
c0e3e13e0a
5 changed files with 37 additions and 21 deletions
|
@ -6,6 +6,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
Changelog
|
Changelog
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
**7.6.0**
|
||||||
|
- Add `wireguard_private_key` variable (contribution by @j8r)
|
||||||
|
- Fix check mode for Debian (contribution by @j8r)
|
||||||
|
|
||||||
**7.5.0**
|
**7.5.0**
|
||||||
|
|
||||||
- `wireguard` package is now available for Ubuntu 18.04 in universe repository. Before that `ppa:wireguard/wireguard` was used but that one isn't available anymore. The install procedure for Ubuntu 18.04 and 20.04 is now the same as both can use `wireguard` metapackage now. The role takes care to remove `wireguard-dkms` package in favour of `wireguard` metapackage but it leaves the configuration file for `ppa:wireguard/wireguard` repository untouched. So it's up to you to remove that PPA. Either use `apt-add-repository --remove ppa:wireguard/wireguard` or remove the file manually at `/etc/apt/sources.list.d/` directory (you man need to run `apt-get update` afterwards).
|
- `wireguard` package is now available for Ubuntu 18.04 in universe repository. Before that `ppa:wireguard/wireguard` was used but that one isn't available anymore. The install procedure for Ubuntu 18.04 and 20.04 is now the same as both can use `wireguard` metapackage now. The role takes care to remove `wireguard-dkms` package in favour of `wireguard` metapackage but it leaves the configuration file for `ppa:wireguard/wireguard` repository untouched. So it's up to you to remove that PPA. Either use `apt-add-repository --remove ppa:wireguard/wireguard` or remove the file manually at `/etc/apt/sources.list.d/` directory (you man need to run `apt-get update` afterwards).
|
||||||
|
|
|
@ -34,3 +34,7 @@ wireguard_ubuntu_update_cache: "true"
|
||||||
|
|
||||||
# Set package cache valid time
|
# Set package cache valid time
|
||||||
wireguard_ubuntu_cache_valid_time: "3600"
|
wireguard_ubuntu_cache_valid_time: "3600"
|
||||||
|
|
||||||
|
# This is sensitive: encrypt it with a tool like Ansible Vault.
|
||||||
|
# If not set, a new one is generated on a blank configuration.
|
||||||
|
# wireguard_private_key:
|
||||||
|
|
|
@ -27,24 +27,26 @@
|
||||||
- wg-install
|
- wg-install
|
||||||
when: not ansible_os_family == 'Darwin'
|
when: not ansible_os_family == 'Darwin'
|
||||||
|
|
||||||
# Key handling [[[1
|
- block:
|
||||||
- name: Register if config/private key already exists on target host
|
# Key handling [[[1
|
||||||
stat:
|
- name: Register if config/private key already exists on target host
|
||||||
path: "{{ wireguard_remote_directory }}/{{ wireguard_interface }}.conf"
|
stat:
|
||||||
register: wireguard__register_config_file
|
path: "{{ wireguard_remote_directory }}/{{ wireguard_interface }}.conf"
|
||||||
|
register: wireguard__register_config_file
|
||||||
|
|
||||||
|
- name: Get wg subcommands
|
||||||
|
command: "wg --help"
|
||||||
|
register: wireguard__register_subcommands
|
||||||
|
changed_when: false
|
||||||
|
check_mode: no
|
||||||
|
|
||||||
|
- name: Check if wg syncconf subcommand is available
|
||||||
|
set_fact:
|
||||||
|
wg_syncconf: "{{ 'syncconf:' in wireguard__register_subcommands.stdout }}"
|
||||||
tags:
|
tags:
|
||||||
- wg-generate-keys
|
- wg-generate-keys
|
||||||
- wg-config
|
- wg-config
|
||||||
|
|
||||||
- name: Get wg subcommands
|
|
||||||
command: "wg --help"
|
|
||||||
register: wireguard__register_subcommands
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: Check if wg syncconf subcommand is available
|
|
||||||
set_fact:
|
|
||||||
wg_syncconf: "{{ 'syncconf:' in wireguard__register_subcommands.stdout }}"
|
|
||||||
|
|
||||||
- name: Show syncconf subcommand status
|
- name: Show syncconf subcommand status
|
||||||
debug:
|
debug:
|
||||||
var: wg_syncconf
|
var: wg_syncconf
|
||||||
|
@ -59,10 +61,12 @@
|
||||||
|
|
||||||
- name: Set private key fact
|
- name: Set private key fact
|
||||||
set_fact:
|
set_fact:
|
||||||
wireguard__fact_private_key: "{{ wireguard__register_private_key.stdout }}"
|
wireguard_private_key: "{{ wireguard__register_private_key.stdout }}"
|
||||||
tags:
|
tags:
|
||||||
- wg-generate-keys
|
- wg-generate-keys
|
||||||
when: not wireguard__register_config_file.stat.exists
|
when:
|
||||||
|
- not wireguard__register_config_file.stat.exists
|
||||||
|
- wireguard_private_key is not defined
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Read WireGuard config file
|
- name: Read WireGuard config file
|
||||||
|
@ -74,17 +78,20 @@
|
||||||
|
|
||||||
- name: Set private key fact
|
- name: Set private key fact
|
||||||
set_fact:
|
set_fact:
|
||||||
wireguard__fact_private_key: "{{ wireguard__register_config['content'] | b64decode | regex_findall('PrivateKey = (.*)') | first }}"
|
wireguard_private_key: "{{ wireguard__register_config['content'] | b64decode | regex_findall('PrivateKey = (.*)') | first }}"
|
||||||
tags:
|
tags:
|
||||||
- wg-config
|
- wg-config
|
||||||
when: wireguard__register_config_file.stat.exists
|
when:
|
||||||
|
- wireguard__register_config_file.stat.exists
|
||||||
|
- wireguard_private_key is not defined
|
||||||
|
|
||||||
- name: Derive WireGuard public key
|
- name: Derive WireGuard public key
|
||||||
command: "wg pubkey"
|
command: "wg pubkey"
|
||||||
args:
|
args:
|
||||||
stdin: "{{ wireguard__fact_private_key }}"
|
stdin: "{{ wireguard_private_key }}"
|
||||||
register: wireguard__register_public_key
|
register: wireguard__register_public_key
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
check_mode: no
|
||||||
tags:
|
tags:
|
||||||
- wg-config
|
- wg-config
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
- name: (Debian) Get architecture
|
- name: (Debian) Get architecture
|
||||||
command: "dpkg --print-architecture"
|
command: "dpkg --print-architecture"
|
||||||
register: wireguard__fact_dpkg_arch
|
register: wireguard__fact_dpkg_arch
|
||||||
changed_when: False
|
changed_when: false
|
||||||
|
check_mode: no
|
||||||
|
|
||||||
- name: (Debian) Install kernel headers metapackage to ensure headers will be installed
|
- name: (Debian) Install kernel headers metapackage to ensure headers will be installed
|
||||||
apt:
|
apt:
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
[Interface]
|
[Interface]
|
||||||
# {{ inventory_hostname }}
|
# {{ inventory_hostname }}
|
||||||
Address = {{ wireguard_address }}
|
Address = {{ wireguard_address }}
|
||||||
PrivateKey = {{ wireguard__fact_private_key }}
|
PrivateKey = {{ wireguard_private_key }}
|
||||||
ListenPort = {{ wireguard_port }}
|
ListenPort = {{ wireguard_port }}
|
||||||
{% if wireguard_dns is defined %}
|
{% if wireguard_dns is defined %}
|
||||||
DNS = {{ wireguard_dns }}
|
DNS = {{ wireguard_dns }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue