From 02739841e95697a4e9230fe4d2c81c8973f839f7 Mon Sep 17 00:00:00 2001
From: Thomas Schneider <thomas@fsmpi.rwth-aachen.de>
Date: Tue, 11 Jan 2022 19:57:26 +0100
Subject: [PATCH] basic-system: fstrim cronjob

---
 basic-system/defaults/main.yml |  1 +
 basic-system/files/fstrim      |  5 +++++
 basic-system/tasks/main.yml    | 11 +++++++++++
 3 files changed, 17 insertions(+)
 create mode 100755 basic-system/files/fstrim

diff --git a/basic-system/defaults/main.yml b/basic-system/defaults/main.yml
index 0b0bcf2..f706b44 100644
--- a/basic-system/defaults/main.yml
+++ b/basic-system/defaults/main.yml
@@ -15,3 +15,4 @@ tmp_mount_options:
   - nosuid
   - nodev
   - noexec
+fstrim: false
diff --git a/basic-system/files/fstrim b/basic-system/files/fstrim
new file mode 100755
index 0000000..b1816b2
--- /dev/null
+++ b/basic-system/files/fstrim
@@ -0,0 +1,5 @@
+#!/bin/sh
+set -e
+if command -v fstrim >/dev/null; then
+    fstrim -a
+fi
diff --git a/basic-system/tasks/main.yml b/basic-system/tasks/main.yml
index 9f0ece0..6b38272 100644
--- a/basic-system/tasks/main.yml
+++ b/basic-system/tasks/main.yml
@@ -54,6 +54,17 @@
   tags:
     - etckeeper
 
+- name: Configure fstrim cronjob
+  copy:
+    src: fstrim
+    dest: /etc/cron.daily/fstrim
+    owner: root
+    group: root
+    mode: '0755'
+  when: fstrim
+  tags:
+    - fstrim
+
 - include: logging.yml
 - meta: flush_handlers
 - include: network.yml
-- 
GitLab