0

I can't seem to find support for the CRON_TZ settings for crontab. How would I configure ansible to run a cron job for a specific timezone?

This is what I want my crontab file to look like. This cron config is currently running on a CentOS 7 box.

/etc/crontab:

# Default Timezone
30 9 * * * bobr /home/bobr/crontest.sh LOCAL "`date -R`"

CRON_TZ=Canada/Eastern
30 11 * * * bobr /home/bobr/crontest.sh Eastern "`date -R`"
45 11 * * * bobr/home/bobr/crontest.sh Eastern "`date -R`"

CRON_TZ=Canada/Pacific
30 8 * * * bobr/home/bobr/crontest.sh Pacific "`date -R`"
44 8 * * * bobr/home/bobr/crontest.sh Pacific "`date -R`"

For reference crontest.sh just sends an email with the 2 parameters:

#!/bin/bash

echo "this is the cron test. $1 $2" | mail -s "Cron Test" bobr@example.com

Hugh
  • 83
  • 1
  • 11
  • I submitted a feature request here: https://github.com/ansible/ansible/issues/64393 – Hugh Nov 08 '19 at 16:04

1 Answers1

0

Didnt find any attribute for timezone set in ansible CRON module.. May be you can try out other way.. using shell..

- name: configure cron using shell
  shell:  crontab cron.conf

and conf file is

cat cron.conf
# Default Timezone
30 9 * * * bobr /home/bobr/crontest.sh LOCAL "`date -R`"

CRON_TZ=Canada/Eastern
30 11 * * * bobr /home/bobr/crontest.sh Eastern "`date -R`"
45 11 * * * bobr/home/bobr/crontest.sh Eastern "`date -R`"

CRON_TZ=Canada/Pacific
30 8 * * * bobr/home/bobr/crontest.sh Pacific "`date -R`"
44 8 * * * bobr/home/bobr/crontest.sh Pacific "`date -R`"
Sai
  • 166
  • 1
  • 8
  • Thank you. I thought about that but was trying to find a more proper way to do this. I may end up just doing a template. – Hugh Nov 04 '19 at 15:26