Kumina | Blog

Puppet Tips&Tricks: Converting booleans to numbers

puppet

puppet

This post is a part of my series about tips and tricks for puppet, the configuration management tool we prefer to use here at Kumina.

Puppet has nice support for Nagios via its Nagios-specific resources. However, this requires you to use “0” and “1” instead of “true” and “false” for booleans in Nagios. Because we like uniformity, I’ve created a little function that simply converts a named boolean to a numerical. Check it out:

module Puppet::Parser::Functions
  newfunction(:bool2num, :type => :rvalue) do |args|
    case args[0]
      when "true"  then "1"
      when "false" then "0"
      when "1"     then "1"
      when "0"     then "0"
      when true    then "1"
      when false   then "0"
      else raise Puppet::ParseError, "Either specify true, false, 1 or 0."
      end
  end
end

Hope this helps someone!

Exit mobile version