Puppet defined resource with cron resource

puppet

In puppet, I am trying to create a defined resource with a cron resource in it. It is for a website that has a batch job that has to be run on certain days.

define website ( $sitename,
             $sitealias,
             $document_root,
             $cronjobs,
             $cron_weekday,
             $cron_minute,
             $cron_hour,

… some other code…

    cron { "${title}-batchjob":
       user => "apache",
       command => "cd ${document_root}/scripts && /usr/bin/php ./batch.php &> /dev/null",
       minute => "${cron_minute}",
       hour =>  "${cron_hour}",
       weekday => "${cron_weekday}",
    }

)

The problem is that if I want to run this cron job on multiple days, say tuesday and thursday, I would have to set $weekday='2,4'.

But to do this, the cron resource defines the weekday parameter as an array.

But how do I pass an array as a variable to the defined resource?

If I declare this refined resource as follows:

website { 'mysite':
    sitename => 'www.mysite.com',
    sitealias => 'mysite',
    document_root => '/var/www/mysite.com',
    cronjobs => true,
    cron_hour => '2',
    cron_minute => '0',
    cron_weekday => '2,4',
}

I get an error saying that 24 is not a valid weekday.

It seems I have to use an array for cron_weekday, but I don't know how to pass a variable as an array in the defined resource.

Best Answer

The problem here is this:

weekday => "${cron_weekday}",

You are basically converting your array to a string.
Change it to:

weekday => $cron_weekday,

And then call pass the parameter like this:

cron_weekday => [2, 4],

And of course do the same for the other variables too.