test_package/ansible_role.yml

30 lines
794 B
YAML

---
- name: Get file modification time
stat:
path: "{{ file_path }}"
register: file_stat
- name: Calculate time since last modification
set_fact:
file_modified_recently: "{{ (ansible_date_time.epoch | int - file_stat.stat.mtime | int) < time_threshold }}"
- name: Debug modification time
debug:
msg: "File was modified recently: {{ file_modified_recently }}"
- name: Skip task if file was modified recently
debug:
msg: "Skipping task as file was modified recently"
when: file_modified_recently
- name: Execute the task if file was not modified recently
command: echo "File was not modified recently, executing the task"
when: not file_modified_recently
defaults/main.yml
---
file_path: "/path/to/your/file"
time_threshold: 600 # 10 minutes (600 seconds)