From ede924e8216fbbb138165dafba26d6f2fed2bdb0 Mon Sep 17 00:00:00 2001 From: Simeon 'n0emis' Keske Date: Tue, 2 Feb 2021 15:08:51 +0100 Subject: [PATCH] allow to remove peers --- tasks/bird2.yml | 11 +++++++++++ tasks/wireguard.yml | 27 +++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/tasks/bird2.yml b/tasks/bird2.yml index c5d75ba..acfb73d 100644 --- a/tasks/bird2.yml +++ b/tasks/bird2.yml @@ -22,6 +22,17 @@ template: dest: "/etc/bird/peers/{{ peer.name }}.conf" src: "bird2/peer.conf.j2" + when: (not peer.state is defined) or peer.state != "absent" + loop: "{{ dn42_peers }}" + loop_control: + loop_var: "peer" + notify: reload bird + +- name: Remove bird peer config-files + file: + path: "/etc/bird/peers/{{ peer.name }}.conf" + state: absent + when: peer.state is defined and peer.state == "absent" loop: "{{ dn42_peers }}" loop_control: loop_var: "peer" diff --git a/tasks/wireguard.yml b/tasks/wireguard.yml index 671e6a4..dd729b6 100644 --- a/tasks/wireguard.yml +++ b/tasks/wireguard.yml @@ -3,21 +3,36 @@ template: dest: "/etc/wireguard/{{ peer.if.name | default(dn42_wg_default_if_prefix + peer.name) }}.conf" src: "wg-quick.j2" - when: "peer.wg is defined" + when: + - peer.wg is defined + - (not peer.state is defined) or peer.state != "absent" register: "configuration" - name: Enable wg-quick@{{ peer.if.name | default(dn42_wg_default_if_prefix + peer.name) }} service service: name: "wg-quick@{{ peer.if.name | default(dn42_wg_default_if_prefix + peer.name) }}" enabled: yes + when: + - peer.wg is defined + - (not peer.state is defined) or peer.state != "absent" - name: Restart wg-quick@{{ peer.if.name | default(dn42_wg_default_if_prefix + peer.name) }} service: name: "wg-quick@{{ peer.if.name | default(dn42_wg_default_if_prefix + peer.name) }}" state: restarted - when: "configuration is changed" - - - - + when: + - "configuration is changed" + - (not peer.state is defined) or peer.state != "absent" +- name: Stop wg-quick@{{ peer.if.name | default(dn42_wg_default_if_prefix + peer.name) }} + service: + name: "wg-quick@{{ peer.if.name | default(dn42_wg_default_if_prefix + peer.name) }}" + state: stopped + enabled: no + when: peer.state is defined and peer.state == "absent" + +- name: Remove wg-quick@{{ peer.if.name | default(dn42_wg_default_if_prefix + peer.name) }} config + file: + path: "/etc/wireguard/{{ peer.if.name | default(dn42_wg_default_if_prefix + peer.name) }}.conf" + state: absent + when: peer.state is defined and peer.state == "absent"