From 0198b3b2e249bbbbde379331d13e376608400b72 Mon Sep 17 00:00:00 2001 From: "mhorak@totalservice.cz" Date: Thu, 14 Aug 2025 16:41:50 +0200 Subject: [PATCH] a --- www-windows-check-free-disk-space.yaml | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/www-windows-check-free-disk-space.yaml b/www-windows-check-free-disk-space.yaml index 78dc5a0..b43809e 100644 --- a/www-windows-check-free-disk-space.yaml +++ b/www-windows-check-free-disk-space.yaml @@ -46,31 +46,37 @@ winre_parts: "{{ [winre_parts] }}" when: winre_parts is mapping - # --- threshold (MiB) -> bytes + # Thresholds - name: Set Recovery size threshold ansible.builtin.set_fact: recovery_threshold_mib: 500 recovery_threshold_bytes: "{{ 500 * 1024 * 1024 }}" changed_when: false - # Smallest Recovery partition on this host (if any) - - name: Compute smallest Recovery partition size (bytes) + # Build a list of sizes as INTS + - name: Extract recovery sizes (bytes → ints) ansible.builtin.set_fact: - recovery_min_bytes: "{{ winre_parts | map(attribute='SizeBytes') | map('int') | list | min }}" - when: winre_parts | length > 0 + recovery_sizes_bytes: "{{ winre_parts | map(attribute='SizeBytes') | map('int') | list }}" changed_when: false - # Fail this host if it has a Recovery partition smaller than 500 MiB + # Compute smallest size (bytes) + - name: Compute smallest Recovery partition size (bytes) + ansible.builtin.set_fact: + recovery_min_bytes: "{{ recovery_sizes_bytes | min }}" + when: recovery_sizes_bytes | length > 0 + changed_when: false + + # Fail this host if smallest Recovery partition < 500 MiB - name: Enforce minimum Recovery partition size ansible.builtin.fail: msg: >- Recovery partition too small on {{ inventory_hostname }}: - smallest={{ (recovery_min_bytes / 1024 / 1024) | round(2) }} MiB, - required >= {{ recovery_threshold_mib }} MiB. + smallest={{ ((recovery_min_bytes | int) / 1048576.0) | round(2) }} MiB, + required >= {{ recovery_threshold_mib | int }} MiB. Details: {{ winre_parts }} when: - - winre_parts | length > 0 - - recovery_min_bytes < recovery_threshold_bytes + - recovery_sizes_bytes | length > 0 + - (recovery_min_bytes | int) < (recovery_threshold_bytes | int) - name: Show Recovery partition sizes ansible.builtin.debug: