Skip to content

Instantly share code, notes, and snippets.

@lanky
Last active August 29, 2015 14:24
Show Gist options
  • Save lanky/08566e684382e57d9c39 to your computer and use it in GitHub Desktop.
Save lanky/08566e684382e57d9c39 to your computer and use it in GitHub Desktop.
- hosts: all
name: test stat output
tasks:
- name: check last change to file
stat:
path: '/etc/fstab'
register: st
- debug:
msg: "File last modified {{ansible_date_time.epoch|int - st.stat.mtime|int }} seconds ago"
- name: run command if file older than one hour
command: /bin/echo "yes"
when: "{{ansible_date_time.epoch|int}} - {{ st.stat.mtime|int }} < 3600"
- name: run command if file older than one hour
command: /bin/echo "no"
when: "{{ansible_date_time.epoch|int}} - {{ st.stat.mtime|int }} >= 3600"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment