From dc56b0d39ef2494ddb348714ca53071642a0c0e5 Mon Sep 17 00:00:00 2001 From: githubixx Date: Sat, 25 Jan 2020 21:49:48 +0100 Subject: [PATCH] use wg syncconf if available --- handlers/main.yml | 12 ++++++++++++ tasks/main.yml | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/handlers/main.yml b/handlers/main.yml index 1063f5e..732e8f5 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,3 +3,15 @@ service: name: "wg-quick@{{ wireguard_interface }}" state: restarted + when: wg_syncconf == "false" + listen: "reconfigure wireguard" + +- name: syncconf wireguard + shell: | + systemctl is-active wg-quick@wg-quick@{{ wireguard_interface|quote }} || systemctl start wg-quick@{{ wireguard_interface|quote }} + wg syncconf {{ wireguard_interface|quote }} <(wg-quick strip /etc/wireguard/{{ wireguard_interface|quote }}.conf) + exit 0 + args: + executable: "/bin/bash" + when: wg_syncconf == "true" + listen: "reconfigure wireguard" diff --git a/tasks/main.yml b/tasks/main.yml index 492f833..04a3770 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -39,6 +39,19 @@ - wg-generate-keys - wg-config +- name: Get wg subcommands + command: "wg --help" + register: wg_subcommands + +- name: Set default value for wg_syncconf variable + set_fact: + wg_syncconf: "false" + +- name: Check if wg syncconf subcommand is available + set_fact: + wg_syncconf: "true" + when: wg_subcommands.stdout | regex_search('syncconf:') + - block: - name: Generate WireGuard private key shell: "wg genkey" @@ -99,7 +112,7 @@ tags: - wg-config notify: - - restart wireguard + - reconfigure wireguard - name: Check if reload-module-on-update is set stat: