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: