36
loading...
This website collects cookies to deliver better user experience
require ‘puppet’
Facter.add(:cem_inetd) do
confine kernel: 'Linux'
...
setcode do
...
end
end
kernel
that resolves to Linux
because that is the only value that the fact has deemed suitable. In other words, only Linux nodes will have this fact; Windows nodes will not, because Puppet will evaluate the condition to prove suitability before execution.confine
that states whether or not the dependencies are installed. You start thinking over your options. confine
. confine
. # lib/puppet/feature/cem_inetd.rb
require 'puppet/util/feature'
Puppet.features.add(:cem_inetd) do
inetd = `sh -c 'command -v inetd'`.strip
xinetd = `sh -c 'command -v xinetd'`.strip
inetd.empty? && xinetd.empty? ? false : true
end
true
, false
, or nil.
Features can then be used with confine
like so:# lib/facter/cem_inetd.rb
require 'puppet'
Facter.add(:cem_inetd) do
confine kernel: 'Linux'
confine { Puppet.features.cem_inetd? }
setcode do
...
end
end
lib/puppet/feature/.
The convention is to name your ruby file after the feature name.true
has that value cached and the feature code will not be executed again on that nodefalse
has that value cached and the feature code will not be executed again on that nodenil
does not cache that value, and the feature code will execute on that node at every Puppet run.false
if the check will never be true in the future. You should return nil
if the check could possibly be true in the future.Puppet.features.<feature name>?
. What this function does is return the cached value of the feature, or run the feature code and cache / return the value. When you use this function with confine
, it is important to remember to pass the feature function inside of a block (the curly braces) because otherwise you will get an error.xinetd
because it listens for network requests to spawn system services (AwesomeApp may not actually be that awesome…), we can reuse the feature from the example code above. Remember, since xinetd
is not something we can reasonably expect to exist on a node at some time in the future, we just return false
if we can’t find it.# lib/puppet/feature/awesome_ruby_deps.rb
require 'puppet/util/feature'
Puppet.features.add(:awesome_ruby_deps, libs: [‘awesome_gem’, ‘gem_awesome’])
add()
function provides a convenience parameter libs
that is specifically used for checking that Puppet has the specified Ruby libraries.confine
instead.