From 2d6e36572b38807259e5a3dba88653f5f19258af Mon Sep 17 00:00:00 2001 From: tjend Date: Mon, 7 Jun 2021 06:06:17 +1000 Subject: [PATCH] Allow disabling service (#107) --- defaults/main.yml | 3 +++ handlers/main.yml | 14 ++++++++------ tasks/main.yml | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index fea6eec..ba13a28 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -24,6 +24,9 @@ wireguard_conf_group: "{{ 'root' if not ansible_os_family == 'Darwin' else 'whee # The default mode of the wg.conf file wireguard_conf_mode: 0600 +# The default state of the wireguard service +wireguard_service_enabled: "yes" +wireguard_service_state: "started" ####################################### # Settings only relevant for Ubuntu diff --git a/handlers/main.yml b/handlers/main.yml index ff612e2..8cfe0a5 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -9,9 +9,10 @@ loop: - stopped - started - when: > - not wg_syncconf and - not ansible_os_family == 'Darwin' + when: + - not wg_syncconf + - not ansible_os_family == 'Darwin' + - wireguard_service_enabled == "yes" listen: "reconfigure wireguard" - name: syncconf wireguard @@ -24,7 +25,8 @@ exit 0 args: executable: "/bin/bash" - when: > - wg_syncconf and - not ansible_os_family == 'Darwin' + when: + - wg_syncconf + - not ansible_os_family == 'Darwin' + - wireguard_service_enabled == "yes" listen: "reconfigure wireguard" diff --git a/tasks/main.yml b/tasks/main.yml index 9f0a42a..b0b9cb9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -133,6 +133,6 @@ - name: Start and enable WireGuard service service: name: "wg-quick@{{ wireguard_interface }}" - state: started - enabled: yes + state: "{{ wireguard_service_state }}" + enabled: "{{ wireguard_service_enabled }}" when: not ansible_os_family == 'Darwin'