I have a custom puppet fact (written in ruby) which executes a simple bash script. The script checks all files in the file system for world-readable permissions and returns results accordingly. The puppet fact checks the output of the script and returns "fail" if the script output is not null.
The problem is that the script is resource intensive and I don't want it to be executed every 30 minutes (client' puppet.conf: runinternval=1800).
I've tried using the "schedule" resource but because of the way puppet works, it only affects the class I'm using to evaluate the fact's output. Puppet facts are evaluated on each puppet run, regardless of anything else. (thus making them available for resources)
I've also tried to move the code that executes the bash script out from the fact and into the puppet class but it appears you cannot evaluate the output of a bash script (using "exec" type) and store it in a variable (again, because of the way puppet works).
I am now reduced to try and apply some kind of scheduling mechanism using Ruby language, and implement it in the fact. I've read a bit on PStore and right now this seems like a good direction.
Does anyone know how I can make a ruby script execute only during night? I cannot use crontab because the code will run by puppet.
Code snippet from the puppet class:
if $::myfact == 'fail' {
notify { "warning blah blah...":
loglevel => err,
schedule => 'night',
}
}
Code snippet from the puppet fact:
require 'facter'
Facter.add(:myfact) do
setcode do
if File.exists? '/usr/local/puppet/scripts/myscript.sh'
result = Facter::Util::Resolution.exec("/usr/local/puppet/scripts/myscript.sh")
if result != ''
puts "Result of myfact is: \n #{result}"
'fail'
end
end
end
end