Puppet Cron 将 $variable 设置为分钟以及 */

Puppet Cron setting $vairable as minute aswell as */

然而,这对我来说很难解释。

我想将时间安排到 puppet 以完成 cron 作业。

define cron::job (
  $url,
  $time_offset,
  $ensure = 'present',
  $minute = 5 + $time_offset,

)

然后在我的实际工作中我想使用 */ 以及 minute 变量。这可能吗?由于我当前的实施失败,而且我似乎无法在文档中找到答案,这表明我正在以完全错误的方式解决这个问题。

这是我的 cron 作业。

  cron { "job":
    command => "wget -O - --save-cookies cookies.txt --load-cookies cookies.txt --keep-session-cookies  https://${url}/ >/dev/null 2>/dev/null",
    user    => 'housekeeper',
    minute  => '*/$minute',
    ensure  => $ensure,
  }

如果有任何反馈/建议,我将不胜感激。

例如,我只使用固定的一分钟而不是每 5 分钟会更好吗?

我想这样做的原因是我想让 cron 作业保持不变,只是将偏移量传递给每个站点的 class。

这个有效:

define cron::job (
  $url,
  $time_offset,
) {
  $minute = 5 + $time_offset
  cron { "cron ${name}":
    ensure  => present,
    command => "wget -O - --save-cookies cookies.txt --load-cookies cookies.txt --keep-session-cookies  https://${url}/ >/dev/null 2>/dev/null",
    user    => 'housekeeper',
    minute  => "*/${minute}",
    require => User['housekeeper'],
  }
}

user { 'housekeeper':
  ensure => present,
}

cron::job { 'job1':
  url => 'http://example1.com',
  time_offset => 10,
}
cron::job { 'job2':
  url => 'http://example2.com',
  time_offset => 15,
}

然后

[root@centos-72-x64 ~]# puppet apply /tmp/foo.pp 
Notice: Compiled catalog for centos-72-x64 in environment production in 0.21 seconds
Notice: /Stage[main]/Main/User[housekeeper]/ensure: created
Notice: /Stage[main]/Main/Cron::Job[job2]/Cron[cron job2]/ensure: created
Notice: /Stage[main]/Main/Cron::Job[job1]/Cron[cron job1]/ensure: created
Notice: Finished catalog run in 0.05 seconds

[root@centos-72-x64 ~]# cat /var/spool/cron/housekeeper
# HEADER: This file was autogenerated at 2016-04-12 11:29:15 +0000 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: cron job2
*/20 * * * * wget -O - --save-cookies cookies.txt --load-cookies cookies.txt --keep-session-cookies  https://http://example2.com/ >/dev/null 2>/dev/null
# Puppet Name: cron job1
*/15 * * * * wget -O - --save-cookies cookies.txt --load-cookies cookies.txt --keep-session-cookies  https://http://example1.com/ >/dev/null 2>/dev/null