Ask Your Question
0

Make cron resource attribute minute as variable to run as separate interval based on some condition

asked 2017-02-21 03:43:31 -0500

smuku gravatar image

if environ == 'prod' { $min == '[5,10,15,20,25]' else $min == '[10,40] }

cron { 'updateyp': command => '/usr/local/script.sh > /dev/null 2>&1', hour => '*', minute => $min, require => [ File['/usr/local/script.shh'], Exec['runscript'] ], }

This currently fails as syntax error

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2017-02-22 08:40:30 -0500

drdam gravatar image

updated 2017-02-22 08:41:56 -0500

are you using hiera? The cleanest solution would be to have the minute parameter in your hiera data. Their you can specify a default value ([10,40] in your example) and a production specific value ([5,10,15,20,25]). That way you don't need the ifstructure. BTW: where do you get the environ parameter from? the default variable would be $::environment

edit flag offensive delete link more
0

answered 2017-02-22 08:39:55 -0500

updated 2017-02-22 08:40:25 -0500

This fails because of a syntax error.

You have to use = for assignment and == for comparison.

However, I usually prefer to use a selector for variable assignments which have to end up with a value assigned to them.

$min = $environ =~ /^prod$/ ? {
  true    => [5, 10, 15, 20, 25],
  default => [10, 40],
}

cron { 'update_yp':
  command => '/usr/local/script.sh > /dev/null 2>&1',
  hour    => '*'
  minute  => $min,
  require => [
      File['/usr/local/script.sh'],
      Exec['run_script'],
    ],
}
  • Were you looking for $environment or $server_facts['environment']?
  • There was a typo in the require attribute (/usr/local/script.shh → /usr/local/script.sh).
  • If you're using/suffering from systemd have a look at systemd.timer(5).
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-02-21 03:40:48 -0500

Seen: 43 times

Last updated: Feb 22