From 91d2fcbf2793b1e2e7b31016c2a712432a8fff69 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Fri, 12 Jun 2020 16:30:06 -0500 Subject: [PATCH] spiped removal --- roles/spiped/handlers/main.yaml | 1 + roles/spiped/tasks/main.yaml | 39 ++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/roles/spiped/handlers/main.yaml b/roles/spiped/handlers/main.yaml index e7d49b8..925f083 100644 --- a/roles/spiped/handlers/main.yaml +++ b/roles/spiped/handlers/main.yaml @@ -8,3 +8,4 @@ name: "spiped-{{ item.name }}" state: restarted loop: "{{ spiped_tunnels | default([]) }}" + no_log: true diff --git a/roles/spiped/tasks/main.yaml b/roles/spiped/tasks/main.yaml index e0b5fd3..d15624c 100644 --- a/roles/spiped/tasks/main.yaml +++ b/roles/spiped/tasks/main.yaml @@ -33,10 +33,12 @@ group: root mode: 0644 loop: "{{ spiped_tunnels | default([]) }}" + when: + - ansible_service_mgr == 'systemd' + - item.state | default('present') == 'present' notify: - - restart spiped tunnels - spiped daemon-reload - when: ansible_service_mgr == 'systemd' + - restart spiped tunnels no_log: true - name: configure keys @@ -47,14 +49,41 @@ group: "{{ spiped_group }}" mode: 0400 loop: "{{ spiped_tunnels | default([]) }}" + when: + - ansible_service_mgr == 'systemd' + - item.state | default('present') == 'present' notify: - restart spiped tunnels no_log: true - name: manage services - service: + systemd: name: "spiped-{{ item.name }}.service" - state: "{{ item.state | default('started') }}" - enabled: "{{ item.enabled | default(true) }}" + state: "{{ (item.state | default('present') == 'absent') | ternary('stopped', 'started') }}" + enabled: "{{ item.state | default('present') != 'absent' }}" + daemon_reload: true loop: "{{ spiped_tunnels | default([]) }}" no_log: true + +- name: remove keys + file: + path: "{{ spiped_etc_path }}/{{ item.name }}.key" + state: "absent" + loop: "{{ spiped_tunnels | default([]) }}" + when: + - item.state is defined + - item.state == "absent" + no_log: true + +- name: remove systemd unit + file: + path: "/etc/systemd/system/spiped-{{ item.name }}.service" + state: "absent" + loop: "{{ spiped_tunnels | default([]) }}" + notify: + - spiped daemon-reload + when: + - ansible_service_mgr == 'systemd' + - item.state is defined + - item.state == "absent" + no_log: true