diff --git a/ansible_role.yml b/ansible_role.yml new file mode 100644 index 0000000..77f31b4 --- /dev/null +++ b/ansible_role.yml @@ -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) +