Ask Your Question

haproxy where will these parameters go in a puppet code?

asked 2018-11-11 06:38:36 -0600

aLuViAn gravatar image

Hi, I'm fairly new to puppet but so far, I've been able to get the tasks done using documentation and communities. But this one I could not find any reference on the documentation and/or in the community forums. The problem is as follows:

There is an existing HAProxy infrastructure and I'm supposed to puppetize it. So, as I don't know much about HAProxy, my goal is to create a puppet script that creates the same haproxy.cfg as the current one. But there are a lot of parameters and lines in the main haproxy.cfg file which I have not been able to find a reference in Forge - or anywhere else - on how to include these in a puppet code.

The part that I'm talking about goes like this in haproxy.cfg :

listen  fooapp-cluster
        mode http
        capture request header X-Forwarded-For len 100
        acl foo_old hdr(host) -i
        redirect prefix code 301 if foo_old
        http-request redirect prefix http://www.%[hdr(host)] code 301 unless { hdr_beg(host) -i www. }  
        balance roundrobin
        maxconn 200000
        server app-fooapp1 check 
        server app-fooapp2 check 
        server app-fooapp3 check 
        server app-fooapp4 check

As you can see, there is a part about header and DNS resolution (starting from capture request header.....ending in hdr_beg(host) -i www. }). As there is no reference and/or sample over the internet, im trying to figure it out with trial and error. This is what I've got so far, which throws error on puppet parser validate in the section that I mentioned:

  haproxy::listen { 'fooapp-cluster':
    collect_exported => false,
    ipaddress        => '*',
    ports            => '80',
    mode             => 'http',
    maxconn          => '200000',
    options          => {
      'mode'         => 'http',
      'balance'      => 'roundrobin',
      'capture request header X-Forwarded-For len 100',
      'acl foo_old hdr(host) -i',
      'redirect prefix code 301 if foo_old',
      'http-request redirect prefix http://www.%[hdr(host)] code 301 unless { hdr_beg(host) -i www. }',],
      'option'       => [

Can someone help me on this issue? I'm quite stuck here and don't know how to move forward. Let me know if you need the complete haproxy.cfg and puppet scripts (Balancermember, default options, etc.).

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-11-16 16:35:57 -0600

vicinus gravatar image

Didn't test it but something like this should work:

haproxy::listen { 'fooapp-cluster':
  collect_exported => false,
  bind => {
    '' => [],
  mode => 'http',
  options => {
    'capture request header' => 'X-Forwarded-For len 100',
    acl => 'foo_old hdr(host) -i',
    'redirect prefix' => ' code 301 if foo_old',
    'http-request' => 'redirect prefix http://www.%[hdr(host)] code 301 unless { hdr_beg(host) -i www. }',
    balance => 'roundrobin',
    maxconn => 200000,
    server => [
      'app-fooapp1 check',
      'app-fooapp2 check',
      'app-fooapp3 check',
      'app-fooapp4 check',

If you have for example multiple acl entries you can write them like the multiple server entries as an array. Also you can split options lines on every space. For example it is possible to write the capture request header this way:

options => {
  capture => 'request header X-Forwarded-For len 100',

We have decided that we split them after the haproxy keyword, but this is just our preference.

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: 2018-11-11 06:38:36 -0600

Seen: 91 times

Last updated: Nov 16