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."

Hope this helps someone!

Tags: , , , , , ,

Comments are closed.

Kumina designs, builds, operates and supports Kubernetes solutions that help companies thrive online. As Certified Kubernetes Service Partner, we know how to build real solutions.