I had the following problem with erb in combination with Puppet, Hiera and templates:
Via Hiera I got the following strings as variables:
First the variable example
in an array (data[example])
something with _VARIABLE_ in it
and variable example_information
with
some kind of \1 and maybe also a \2
Now I wanted to substitute _VARIABLE_
in a Puppet template with the second string which contains a legit backslash () in it. So I did it like this:
result=data['example'].gsub('_VARIABLE_', @example_information)
So I took example
out of an array and filled the placeholder with @example_information
.
The result was as follows:
something with some kind of and maybe also a in it
There was no backslash as gsub
interpreted them as backreferences. So how can I solve my issue to preserve my backslashes without double escape them in the Hiera file? I need the Hiera variable further in the code without double escaped backslashes.