From 302386892455fd661afed690ef6fed6d7672a616 Mon Sep 17 00:00:00 2001
From: Jens Steidl <Jens.Steidl@slub-dresden.de>
Date: Thu, 30 Jun 2022 08:40:54 +0200
Subject: [PATCH] fix: remove cache file only if legacy tools were found

---
 tasks/install-repair-tools.yml | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/tasks/install-repair-tools.yml b/tasks/install-repair-tools.yml
index a6c2dec..7ff937f 100644
--- a/tasks/install-repair-tools.yml
+++ b/tasks/install-repair-tools.yml
@@ -18,15 +18,22 @@
   when: "ansible_facts['distribution'] == 'Debian'"
 
 - name: cleanup legacy tools
-  file:
-    path: "{{ item }}"
-    state: absent
-  loop:
-    - "/usr/local/bin/checkit_tiff"
-    - "/usr/local/bin/fixit_tiff"
-    - "/home/{{ vault_service_user }}/.cache/SLUB_LZA_Reparaturtool.cache"
-    - "/etc/cit_tiff6_baseline_SLUB.cfg"
-  notify: restart repairtools
+  block:
+    - name: remove legacy tools
+      file:
+        path: "{{ item }}"
+        state: absent
+      loop:
+        - "/usr/local/bin/checkit_tiff"
+        - "/usr/local/bin/fixit_tiff"
+        - "/etc/cit_tiff6_baseline_SLUB.cfg"
+      register: remove_legacy_tools
+    - name: remove legacy cache file
+      file:
+        path: "/home/{{ vault_service_user }}/.cache/SLUB_LZA_Reparaturtool.cache"
+        state: absent
+      notify: restart repairtools
+      when: remove_legacy_tools.changed  # remove cache file only if legacy tools were found
 
 - name: install repairtool (package dependencies are encoded in the package)
   apt:
-- 
GitLab