Make sure, Ansible only runs once after multiple reboots during a specified timeframe
This commit is contained in:
24
local.yml
24
local.yml
@@ -6,9 +6,31 @@
|
|||||||
vars_files:
|
vars_files:
|
||||||
- "os_vars/{{ ansible_distribution | lower }}.yml"
|
- "os_vars/{{ ansible_distribution | lower }}.yml"
|
||||||
become: true
|
become: true
|
||||||
|
vars:
|
||||||
|
ansible_reboot_cooldown_minutes: 15 # Cooldown in Minuten
|
||||||
|
ansible_pull_marker_file: /var/tmp/ansible_pull.last_run
|
||||||
|
|
||||||
pre_tasks:
|
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
|
apt: update_cache=yes
|
||||||
#changed_when: false
|
#changed_when: false
|
||||||
when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]
|
when: ansible_distribution in ["Debian", "Ubuntu", "Linux Mint"]
|
||||||
|
|||||||
Reference in New Issue
Block a user