Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppet - Escaping YAML variables for Hiera

I have a pretty simple requirement, but I've tried every escape sequence I can think of, but can't get the output needed.

I need to litterally output into a file:

%{VAR}

Here's my YAML file:

myclass::outputstuff:
    - Heres a litteral var %{VAR}
    - Heres something else %{SOMETHING}

And my template.erb:

<%= @outputstuff.each do | ostuff | -%>
<%= ostuff -%>
<% end -%>

But it like this, it outputs:

Heres a litteral var
Heres something else

If I add a percent sign like %%{VAR}, as advised by other posts, it outputs:

Heres a litteral var %
Heres something else %

If I add a backslash like %\{VAR} it outputs:

Heres a litteral var %\{VAR}
Heres something else %\{SOMETHING}

I need this lol:

Heres a litteral var %{VAR}
Heres something else %{SOMETHING}
like image 943
Just Lucky Really Avatar asked Oct 19 '25 13:10

Just Lucky Really


2 Answers

With Hiera 3.3.1 you can use this in your YAML:

%%{}{EXAMPLE}

Which will output this literal:

%{EXAMPLE}
like image 174
bryan kennedy Avatar answered Oct 22 '25 00:10

bryan kennedy


From v2.0.0 on, there is the literal function, which is the more 'proper' way to do it:

%{literal('%')}{VAR}
like image 24
Chamila Chulatunga Avatar answered Oct 21 '25 23:10

Chamila Chulatunga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!