I have an Ansible task which renews a LetsEncrypt certificate. I only want this task to run once a week, in order to avoid getting blocked for hammering the API, but the rest of the playbook needs to run daily — and will be run way more than that during development.
Is it possible to rate-limit an Ansible task so it will be skipped if it has already been run in the last n hours?
The best way I can think of is to touch a file if the task was run, and skip the task if the file exists and is newer than a certain timestamp — but Ansible doesn't seem to be big on date and time calculations. It also makes the playbook pretty chunky.
I did think of applying a tag to the task and marking the tag as skipped by default in ansible.cfg
, then only running with that tag enabled once a week, but ansible.cfg
seems to override --tags
rather than the other way around.