# Execute task in a playbook only once per day ?

**URL:** <https://forum.ansible.com/t/execute-task-in-a-playbook-only-once-per-day/15454>\
**Category:** Ansible Project\
**Created:** [June 12, 2014, 5:34pm UTC](https://forum.ansible.com/t/execute-task-in-a-playbook-only-once-per-day/15454 "2014-06-12T17:34:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Azul](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Azul](https://forum.ansible.com/u/Azul)\
**Post date:** [June 12, 2014, 5:34pm UTC](https://forum.ansible.com/t/execute-task-in-a-playbook-only-once-per-day/15454/1 "2014-06-12T17:34:56Z")

</div>

Hi there,

I saw an example sometime ago, either a thread,blog or IRC about executing a single task in a playbook only once every 24 hours.  
Can’t find that example anywhere,

has anyone here has an example of how to achieve this ?

I have a task that syncs a mirror with a bunch of upstream repos, and I need to run the playbook for that role fairly frequently but I need to be polite and not try to contact the upstream mirrors every time I run that playbook.

thanks

---

<div class="post-metadata">

**Author:** ![Azul](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@Azul](https://forum.ansible.com/u/Azul)\
**Post date:** [June 13, 2014, 9:15am UTC](https://forum.ansible.com/t/execute-task-in-a-playbook-only-once-per-day/15454/2 "2014-06-13T09:15:35Z")

</div>

sorted,

- 15 - name: check when we last downloaded from upstream
- 14 command: find /var/tmp/ -atime 1 -name “last-upstream-fetch”
- 13 register: result
- 12 ignore\_errors: true
- 11  
10 - include: sync-upstream-repositories.yaml
- 9 when: result != ‘/var/tmp/last-upstream-fetch’ 8  
7 - include: sync-python-repositories.yaml
- 6 when: result != ‘/var/tmp/last-upstream-fetch’  
5  
4 - include: update-yum-repos-metadata.yaml
- 3 when: result != ‘/var/tmp/last-upstream-fetch’
- 2
- 1 - name: update /var/tmp/last-upstream-fetch
- 26 command: touch /var/tmp/last-upstream-fetch  
1

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 13, 2014, 5:59pm UTC](https://forum.ansible.com/t/execute-task-in-a-playbook-only-once-per-day/15454/3 "2014-06-13T17:59:14Z")

</div>

You could modify a file with a result when you run a step and use the ‘stat’ module to check the mtime of the file.
