# Check file for staleness or comparing ctime to current time in Ansible

**URL:** <https://forum.ansible.com/t/check-file-for-staleness-or-comparing-ctime-to-current-time-in-ansible/17176>\
**Category:** Ansible Project\
**Created:** [January 3, 2015, 9:19pm UTC](https://forum.ansible.com/t/check-file-for-staleness-or-comparing-ctime-to-current-time-in-ansible/17176 "2015-01-03T21:19:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mirko\_Friedenhagen](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Mirko\_Friedenhagen](https://forum.ansible.com/u/Mirko_Friedenhagen)\
**Post date:** [January 3, 2015, 9:19pm UTC](https://forum.ansible.com/t/check-file-for-staleness-or-comparing-ctime-to-current-time-in-ansible/17176/1 "2015-01-03T21:19:59Z")

</div>

Hello,

I want to use Ansible for updating Jenkins plugins. So I download the  
update information via curl. I do not want to do this every time I run  
the playbook but only when the downloaded file is stale, say older  
than one day.

I know how to get the stat of the file:  
- name: Check Jenkins plugin data is not too old.  
&nbsp;&nbsp;stat:  
&nbsp;&nbsp;&nbsp;&nbsp;path: /var/lib/jenkins/updates/default.json  
&nbsp;&nbsp;register: jenkins\_updates\_json\_stat

Now I want to execute the download and update steps only when  
jenkins\_updates\_json\_stat.stat.ctime + 86400 \< time.time()

Is there a simple way to get the current time in Ansible?

Regards Mirko

---

<div class="post-metadata">

**Author:** ![Tom\_Bamford](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@Tom\_Bamford](https://forum.ansible.com/u/Tom_Bamford)\
**Post date:** [January 4, 2015, 6:59pm UTC](https://forum.ansible.com/t/check-file-for-staleness-or-comparing-ctime-to-current-time-in-ansible/17176/2 "2015-01-04T18:59:28Z")

</div>

Hi Mirko

Ansible provides the current time in various formats as facts. `ansible_date_time.epoch` could be what you need?

Regards  
Tom

---

<div class="post-metadata">

**Author:** ![Mirko\_Friedenhagen](https://avatars.discourse-cdn.com/v4/letter/m/838e76/32.png) [@Mirko\_Friedenhagen](https://forum.ansible.com/u/Mirko_Friedenhagen)\
**Post date:** [January 4, 2015, 8:25pm UTC](https://forum.ansible.com/t/check-file-for-staleness-or-comparing-ctime-to-current-time-in-ansible/17176/3 "2015-01-04T20:25:12Z")

</div>

Thanks, Tom, I will give it a try.  
Regards Mirko
