From 5c7420d284e4ae74d554b152fc8556ba4e187fa8 Mon Sep 17 00:00:00 2001 From: "pulsar89.5" Date: Wed, 3 May 2023 16:12:42 +0200 Subject: [PATCH] =?UTF-8?q?[EVO]=20Permettre=20de=20ne=20pas=20red=C3=A9ma?= =?UTF-8?q?rrer=20les=20services?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++++++ defaults/main.yml | 2 +- handlers/main.yml | 23 +++++++++++++++++++++++ tasks/configuration.yml | 33 +++++++++++++++++++++++---------- 4 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 handlers/main.yml diff --git a/README.md b/README.md index d0e6e6c..919ee3f 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,12 @@ Variable permettant de déployer le module (dkms) de wireguard sur l'hôte qui h *Valeur par défaut: aucune* +### wireguard_restart_services + +Redémarrer les services si la configuration a été modifiée. + +*Valeur par défaut: `true`* + ### wireguard_interfaces Configuration des interfaces de wireguard (`/etc/wireguard/wgX.conf`). diff --git a/defaults/main.yml b/defaults/main.yml index 113425f..4640a2d 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -2,7 +2,7 @@ # defaults file for wireguard wireguard_module_host: "" -wireguard_listen_port: "" +wireguard_restart_services: true wireguard_interfaces: [] # Exemple: diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..213edf6 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,23 @@ +--- +# handlers file for wireguard + +- name: Activer les services + ansible.builtin.systemd: + enabled: true + name: wg-quick@wg{{ item }}.service + become: true + loop: "{{ deploy.results | selectattr('changed', 'equalto', true) | map(attribute='index') }}" + loop_control: + index_var: index + label: wg{{ index }} + +- name: Redémarrer les services + ansible.builtin.systemd: + state: restarted + name: wg-quick@wg{{ item }}.service + when: wireguard_restart_services + become: true + loop: "{{ deploy.results | selectattr('changed', 'equalto', true) | map(attribute='index') }}" + loop_control: + index_var: index + label: wg{{ index }} diff --git a/tasks/configuration.yml b/tasks/configuration.yml index 5b74789..4cc2517 100644 --- a/tasks/configuration.yml +++ b/tasks/configuration.yml @@ -16,14 +16,27 @@ interface: wg{{ index }} become: true register: deploy + notify: + - Activer les services + - Redémarrer les services -- name: Activer et redémarrer les services - ansible.builtin.systemd: - state: restarted - enabled: true - name: wg-quick@wg{{ item }}.service - become: true - loop: "{{ deploy.results | selectattr('changed', 'equalto', true) | map(attribute='index') }}" - loop_control: - index_var: index - label: wg{{ index }} +#- name: Activer les services +# ansible.builtin.systemd: +# state: restarted +# enabled: true +# name: wg-quick@wg{{ item }}.service +# become: true +# loop: "{{ deploy.results | selectattr('changed', 'equalto', true) | map(attribute='index') }}" +# loop_control: +# index_var: index +# label: wg{{ index }} +# +#- name: Redémarrer les services +# ansible.builtin.systemd: +# state: restarted +# name: wg-quick@wg{{ item }}.service +# become: true +# loop: "{{ deploy.results | selectattr('changed', 'equalto', true) | map(attribute='index') }}" +# loop_control: +# index_var: index +# label: wg{{ index }}