Ask Your Question

Having trouble converting YAML into LogFormat statement

asked 2016-01-29 13:19:13 -0500

AlRad gravatar image

I'm trying to work out the correct YAML syntax that would produce the following statement in /etc/httpd/conf/httpd.conf via Hiera):

LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" extended

After several attempts, I wind up with one of three results:

LogFormat "%v %h %l %u %t "%r" %s %b "i" "i"" extended
             --   or  --
LogFormat "%v %h %l %u %t "%r" %s %b "\i" "\i"" extended
             --   or  --
LogFormat "%v %h %l %u %t "%r" %s %b "%\{Referer\}i" "%\{User-Agent\}i"" extended

(Here is the YAML that produced the above:)

    extended: "%v %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\""
                 --   or  --
    extended: "%v %h %l %u %t \"%r\" %s %b \"\%{Referer}i\" \"\%{User-Agent}i\""
                 --   or  --
    extended: "%v %h %l %u %t \"%r\" %s %b \"%\{Referer\}i\" \"%\{User-Agent\}i\""

I've tried several other combinations in attempts to comment out either the "%" or the "{" from being interpreted somewhere to no avail. Help!!

My environment:

  • CentOS 6.6
  • Puppet 3.7.0
  • puppetlabs-apache 1.7.1

Thank you for any assistance!


edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2016-01-31 05:17:03 -0500

jaxim gravatar image

updated 2016-01-31 05:20:01 -0500

Hi Allen,

I have tested this based on your environment setup. Version of hiera I think you would be using is hiera 1.3.4:

Hiera YAML:

    extended: "%v %h %l %u %t \\\"%r\\\" %>s %b \\\"%%{FOO}{Referer}i\\\" \\\"%%{BAR}{User-Agent}i\\\""

And this gave me the following in /etc/httpd/conf/httpd.conf:

LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" extended

%{FOO} and %{BAR} refer to something that doesn't exist and used to interpret the %. This is based on HI-127. Version 2 of hiera introduced the literal() function to help with escaping.

edit flag offensive delete link more


Thank you, that worked! You are correct, I have hiera 1.3.4 installed so the workaround you suggested did the trick.

AlRad gravatar imageAlRad ( 2016-02-01 09:54:38 -0500 )edit

answered 2016-01-31 04:48:07 -0500

It's explained in HI-127 how to do this.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-01-29 10:42:44 -0500

Seen: 66 times

Last updated: Jan 31 '16