openstack-ansible/playbooks/roles/system_crontab_coordination/templates/crontab.j2
ekultails 7c642cc4df Change the variable name play_hosts to ansible_play_hosts
Starting in Ansible 2.2, the play_hosts variable has been renamed to ansible_play_hosts. play_hosts is now deprecated and may be removed in a future release of Ansible.
Reference: http://docs.ansible.com/ansible/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts

Closes-Bug: 1674947
Change-Id: I3540aee86c0fd3a2b0bf086d4770b765aa1a052e
2017-06-25 11:39:22 -04:00

52 lines
3.6 KiB
Django/Jinja

# {{ ansible_managed }}
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
{% macro normalise(value, start, end, minimum, maximum, period) -%}
{% set v = ((value | int) % (period | int)) + (start | int) %}
{%- if ((v | int) > (maximum | int)) -%}
{{ ((v | int) - (maximum | int) + (minimum | int) - 1) }}
{%- else -%}
{{ v }}
{%- endif -%}
{%- endmacro %}
{% macro set_period(start, end, maximum, minimum) -%}
{{ (((start | int) > (end | int)) | ternary(((maximum | int) - (minimum | int) - (start | int) + (end | int) + 2), ((end | int) - (start | int) + 1))) | int }}
{%- endmacro %}
{% macro set_offset(period, hosts) -%}
{%- if ((hosts | length) | int) > (period | int) -%}
0
{%- else -%}
{{ (((period | int) / ((hosts | length) | int)) | int) | random }}
{%- endif -%}
{%- endmacro %}
{% for host in ansible_play_hosts %}
{% if host == inventory_hostname %}
{% set minute_period = set_period(minute_start, minute_end, 59, 0) | int %}
{% set minute_offset = set_offset(minute_period, ansible_play_hosts) | int %}
{% set number_of_minute_jobs = (4 | int) %}
{% set m = normalise((((minute_period * loop.index) / loop.length) + ((minute_offset | int) / (number_of_minute_jobs | int))), minute_start, minute_end, 0, 59, minute_period) | int %}
{% set hour_period = set_period(hour_start, hour_end, 23, 0) | int %}
{% set hour_offset = set_offset(hour_period, ansible_play_hosts) | int %}
{% set number_of_hour_jobs = (3 | int) %}
{% set h = normalise((((hour_period * loop.index) / loop.length) + ((hour_offset | int) / (number_of_hour_jobs | int))), hour_start, hour_end, 0, 23, hour_period) | int %}
{% set day_of_week_period = set_period(day_of_week_start, day_of_week_end, 6, 0) | int %}
{% set day_of_week_offset = set_offset(day_of_week_period, ansible_play_hosts) | int %}
{% set dow = normalise((((day_of_week_period * loop.index) / loop.length) + (day_of_week_offset | int)), day_of_week_start, day_of_week_end, 0, 6, day_of_week_period) | int %}
{% set day_of_month_period = set_period(day_of_month_start, day_of_month_end, 28, 1) | int %}
{% set day_of_month_offset = set_offset(day_of_month_period, ansible_play_hosts) | int %}
{% set dom = normalise((((day_of_month_period * loop.index) / loop.length) + (day_of_month_offset | int)), day_of_month_start, day_of_month_end, 1, 28, day_of_month_period) | int %}
{{ m }} * * * * root cd / && run-parts --report /etc/cron.hourly
{{ normalise((m + (minute_period * 1 / (number_of_minute_jobs | int))), minute_start, minute_end, 0, 59, minute_period) }} {{ h }} * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
{{ normalise((m + (minute_period * 2 / (number_of_minute_jobs | int))), minute_start, minute_end, 0, 59, minute_period) }} {{ normalise((h + (hour_period * 1 / (number_of_hour_jobs | int))), hour_start, hour_end, 0, 23, hour_period) }} * * {{ dow }} root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
{{ normalise((m + (minute_period * 3 / (number_of_minute_jobs | int))), minute_start, minute_end, 0, 59, minute_period) }} {{ normalise((h + (hour_period * 2 / (number_of_hour_jobs | int))), hour_start, hour_end, 0, 23, hour_period) }} {{ dom }} * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
{% endif %}
{% endfor %}
#