Add ansible_role.yml
This commit is contained in:
parent
d498947afc
commit
0c5c75cae0
|
|
@ -0,0 +1,29 @@
|
||||||
|
---
|
||||||
|
- 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)
|
||||||
|
|
||||||
Loading…
Reference in New Issue