在 Puppet 中将变量转换为字符串

Converting variable to string in Puppet

是否可以在Puppet中将Boolean变量转换为String?我想在替换字符串时使用它。我可以使用条件语句,但也许没有必要。

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

像这样

我建议为此使用 puppetlabs-stdlib 函数:

bool2str

使用可选提供的参数将布尔值转换为字符串。可选的第二个和第三个参数分别表示转换为 true 和 false 的内容。如果只给出一个参数,它将从布尔值转换为包含 'true' 或 'false'.

的字符串 例子:
bool2str(true)                    => 'true'
bool2str(true, 'yes', 'no')       => 'yes'
bool2str(false, 't', 'f')         => 'f'
Requires a single boolean as input. Type: rvalue.