Puppet Function: role::translate_with_map
- Defined in:
- functions/translate_with_map.pp
- Function type:
- Puppet Language
Overview
Translate a role by executing a gsubstr(pattern, value, āGā) with patterns and values from the provided map.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'functions/translate_with_map.pp', line 13
function role::translate_with_map(
String $role,
Hash[
Variant[String, Regexp],
String
] $map,
Boolean $strict = false,
) >> String {
$map.reduce($role) |String $memo, Tuple[Variant[String, Regexp], String] $translate| {
if $translate[1] in $role {
if $strict {
fail("Role includes remapped values: '${translate[1]}' found in '${role}'")
}
else {
warning("Role includes remapped values: '${translate[1]}' found in '${role}'")
}
}
$memo.regsubst($translate[0], $translate[1], 'G')
}
}
|