Ask Your Question

Having trouble converting YAML into LogFormat statement

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

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 -0600

jaxim gravatar image

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

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 -0600 )edit

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

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 -0600

Seen: 183 times

Last updated: Jan 31 '16