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

528 views
Skip to first unread message

Mirko Friedenhagen

unread,
Jan 3, 2015, 4:20:43 PM1/3/15
to ansible-project
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.
stat:
path: /var/lib/jenkins/updates/default.json
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
--
http://illegalstateexception.blogspot.com/
https://github.com/mfriedenhagen/ (http://osrc.dfm.io/mfriedenhagen)
https://bitbucket.org/mfriedenhagen/

Tom Bamford

unread,
Jan 4, 2015, 1:59:52 PM1/4/15
to ansible...@googlegroups.com

Hi Mirko

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

Regards
Tom


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAK8jvqy%2Bqms-C7KrkC%2BMoYc-iFG00dmjrGMUJkgzzvv5ac7r1A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Mirko Friedenhagen

unread,
Jan 4, 2015, 3:25:56 PM1/4/15
to ansible-project
Reply all
Reply to author
Forward
0 new messages