Execute task in a playbook only once per day ?

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

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

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.