Puppet Tips&Tricks: Converting booleans to numbers

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!

Tags: , , , , , ,


Leave a Reply

Kumina helps companies innovate with the power of open source software. As specialists in managed IT operations since 2007, our mission is simple: building and managing the perfectly tailored technical infrastructures that allow our clients to thrive.

With fully managed solutions, we help our customers unlock the full potential of the cloud and Kubernetes. Our team also supports organisations with IT consulting and Kubernetes training courses. Learn more about our services or get in touch, we would love to hear about your business and projects.