So I'm getting adjusted to the immutable variables in puppet, now looking for some advice, or clarification to whether I'm already on the right track.
I have a directory I'd like to sync, but potentially a number of subdirectories thereof. So I'd like to build up an array of one or more paths to pass to a recursive file resource. Ideally, I'd have something like this
$paths = ['fist/path'] # assume this is provided via class parameter
# this should work, since it's only overriding what was provided from higher scope
if($condition) {
$paths += 'second/path'
}
# this won't fly, since $paths has already been set once locally
if($another_condition) {
$paths += 'third/path'
}
but I can't do that, right, since the variables are immutable. What I've come up with as a 'best' approach so far is something like this
$paths = ['fist/path']
if($condition) {
$condition_1_path = ['second/path']
} else {
$condition_1_path = []
}
if($another_condition) {
$condition_2_path = ['third/path']
} else {
$condition_2_path = []
}
$paths = concat($paths, $condition_1_path, $condition_2_path)
I'm unsure if concat will omit an entry from the result if it's provided an empty array for one of its arguments, but waiting to test that once I figure out how to get stdlib loaded.
Either way, looking at this code, to me, it's plain hideous. Is there a cleaner way to do something like this?
It is ugly, but I have done it like this.