how to escape %{ in hiera

1,087 views
Skip to first unread message

Simon

unread,
Jun 6, 2016, 9:20:46 AM6/6/16
to Puppet Users
Hi all

does anyone know how i can escape %{ in hiera without it trying to convert to variable?

i want to add the following to configure a syslog filter for logstash

match => { "message" => "<%{POSINT:syslog_pri}>%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: %{GREEDYDATA:syslog_message}"}


problem is it will try and convert to variables so only shows the following on the server


match => { "message" => "<>  (?:\[\])?: "}


i have tried all the methods i can think of,  any help would be appreciated.


cheers

S

Christopher Wood

unread,
Jun 6, 2016, 9:42:19 AM6/6/16
to puppet...@googlegroups.com
I ran into this too, use the literal function.

$ grep -rh literal hieradata/
testing::cwood1::param3: "%{literal('%')}{::hostname}"
testing::cwood1::param3: "%{literal('%')}{::hostname}"

https://docs.puppet.com/hiera/3.1/variables.html#the-literal-lookup-function
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [1]puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> [2]https://groups.google.com/d/msgid/puppet-users/c1d3661a-ee9c-4460-bb13-be23b210ddb7%40googlegroups.com.
> For more options, visit [3]https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1. mailto:puppet-users...@googlegroups.com
> 2. https://groups.google.com/d/msgid/puppet-users/c1d3661a-ee9c-4460-bb13-be23b210ddb7%40googlegroups.com?utm_medium=email&utm_source=footer
> 3. https://groups.google.com/d/optout

Rob Nelson

unread,
Jun 6, 2016, 10:28:24 AM6/6/16
to puppet...@googlegroups.com
Literal works when there is only one literal percent sign; last I checked, you cannot use it twice in the same value. You can use "%%{::}{::hostname}" to return "%{::hostname}" - the middle "%{::}" returns nothing and splits the first percent from the variable name at the end, preventing interpolation there. 

The use of the two semi colons was to avoid a scoping issue that cropped up as a regression around the puppet 4.3 timeframe that "%%{}{::hostname}" would run into. It is possible this has been fixed by now and the naked semi colons in the braces are optional, but I have not tested this with the latest version of puppet myself. 
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/20160606134212.GA8045%40iniquitous.heresiarch.ca.
For more options, visit https://groups.google.com/d/optout.


--

Simon

unread,
Jun 6, 2016, 12:15:57 PM6/6/16
to Puppet Users
Hi Rob,

That worked perfectly 

thanks!!
Reply all
Reply to author
Forward
0 new messages