Search code examples
rubypuppet

Converting variable to string in Puppet


Is it possible to convert Boolean variable to String in Puppet? I want to use it when replacing string. I can use conditional statement but maybe it is not necessary.

$variable = true
$my_string = "status _"
$string = regsubst($my_string, '_', $variable)

Something like this


Solution

  • I'd recomend using the puppetlabs-stdlib function for this:

    bool2str

    Converts a boolean to a string using optionally supplied arguments. The optional second and third arguments represent what true and false are converted to respectively. If only one argument is given, it is converted from a boolean to a string containing 'true' or 'false'.

    Examples:
    bool2str(true)                    => 'true'
    bool2str(true, 'yes', 'no')       => 'yes'
    bool2str(false, 't', 'f')         => 'f'
    Requires a single boolean as input. Type: rvalue.