From 54fc2ad53527e6e21bd27f549104e7cd9493a386 Mon Sep 17 00:00:00 2001 From: Rene Mewissen Date: Wed, 1 Oct 2025 13:51:07 +0200 Subject: [PATCH] Make sure, Ansible only runs once after multiple reboots during a specified timeframe --- local.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/local.yml b/local.yml index 53b5eeb..fb83b88 100644 --- a/local.yml +++ b/local.yml @@ -6,9 +6,31 @@ vars_files: - "os_vars/{{ ansible_distribution | lower }}.yml" become: true + vars: + ansible_reboot_cooldown_minutes: 15 # Cooldown in Minuten + ansible_pull_marker_file: /var/tmp/ansible_pull.last_run pre_tasks: - - name: pre-run | update apt repository (debian, ubuntu, etc.) + - name: pre-run | get status of marker file + stat: + path: "{{ ansible_pull_marker_file }}" + register: marker_file_stat + tags: always + + - name: pre-run | check if last run was within cooldown period + meta: end_play + when: + - marker_file_stat.stat.exists + - (ansible_date_time.epoch | int) - (marker_file_stat.stat.mtime | int) < (ansible_reboot_cooldown_minutes | int * 60) + tags: always + + - name: pre-run | update marker file timestamp + file: + path: "{{ ansible_pull_marker_file }}" + state: touch + tags: always + + - name: pre-run | update apt repository (debian, ubuntu, etc.) # noqa no-changed-when apt: update_cache=yes #changed_when: false when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]