A schedule sounds like it'll provide what you're looking for. First you create a schedule resource that specifies when things can run and how many times in a given period.
schedule { "slow":
range => "1 - 5",
period => daily,
repeat => 1,
}
The example above will only be evaluated or run during the hours of 1am and 5am and a maximum of once. You can remove the range
parameter and it'll run any time of the day, but again, only once.
On resources, you then specify the schedule
meta-parameter to link them to the above schedule:
exec { "example":
command => "/usr/bin/foo",
unless => "/usr/bin/bar",
schedule => "slow",
}
When you run Puppet with --debug
, you'll now see the following if it's already been evaluated the given number of times, or the range isn't applicable:
debug: /Stage[main]//Exec[example]: Not scheduled
If you've got a few resources, you could use resource defaults inside the class you're restricting to affect all resources of the same type:
Exec {
schedule => "slow",
}
You'd need to do this for each resource type - Exec, File, Augeas etc.
Couple of notes on improving this:
- I don't know a way to apply it to all types of resources in the class
- Applying the
schedule
meta-parameter to a class doesn't appear to work, might be worth raising a bug
Best Answer
As I recall you can't do it directly. Something like this might work though:
(the split/inline_template is based off of something from http://www.crobak.org/2011/02/two-puppet-tricks-combining-arrays-and-local-tests/ )