Re: Backend Configuration Templating

2013-02-06 Thread Holger Just

Hi

Michael Glenney wrote:

We do something similar with chef where we've turned each backend
config associated with an application into json and can dynamically
build configs based on an application list. Completely avoiding using
a template.


In my HAProxy Chef cookbook[1], I have defined resources to generate 
sections (global, default, listen, frontend, backend) into individual 
files from custom templates. This is because I found configurations to 
be too complex to be able to transform them into a tree structure 
without loosing flexibility (and understandability).


These section files are then concatenated to a single config file during 
reload using a simple shell script[2].


Using this technique, the user of the cookbook is able to write 
customized templates which can e.g. loop over search results and 
dynamically create complete configs similar to what Robin Lee Powell showed.


Alternatively, in Chef 11 which was released about two days ago, you can 
create directly create a single config file from partial templates 
without having to first create single files.


If you don't use Chef, there are a couple of other scripts which concat 
your partial config into a full config file. One by me [3] written in 
python, and another in Ruby by Joe Williams[4]. These are intended to be 
used as part of an init script. An example can be found in the repo of [3].


--Holger

[1] https://github.com/meineerde-cookbooks/haproxy
[2] 
https://github.com/meineerde-cookbooks/haproxy/blob/master/files/default/haproxy_join 


[3] https://github.com/finnlabs/haproxy
[4] https://github.com/joewilliams/haproxy_join



Re: Backend Configuration Templating

2013-02-05 Thread Michael Glenney
We do something similar with chef where we've turned each backend config 
associated with an application into json and can dynamically build configs 
based on an application list. Completely avoiding using a template. 

That being said would love to see haproxy support includes.

Michael Glenney
Sent from my iPhone

On Feb 5, 2013, at 2:59 PM, Robin Lee Powell  wrote:

> This is what we do, using puppet's erb templating system:
> 
><% haproxy_https_servers.keys.each do |server| %>
>  <% haproxy_https_servers[server].each do |subserver| %>
><% extra_conditions=''
>if subserver.has_key?('extra_conditions')
>  extra_conditions=subserver['extra_conditions']
>end %>
># content switching based on cookie, having had them set in 
> previous sessions
>use_backend <%= server %>-https-<%= subserver['name'] %> if { 
> hdr_sub(cookie) SITE=<%= server %> } <%= extra_conditions %>
># content switching based on SNI
>use_backend <%= server %>-https-<%= subserver['name'] %> if { 
> ssl_fc_sni -i <%= server %> } <%= extra_conditions %>
>  <% end %>
><% end %>
> 
> -Robin
> 
> On Tue, Feb 05, 2013 at 02:53:13PM -0700, William Attwood wrote:
>> I would imagine you would dynamically create the haproxy configuration
>> based on the sources you're using to fill your variables.  I'll be doing
>> something similar, soon, where the configuration is dynamically built based
>> on entries in a database.
>> 
>> 
>> Thank you,
>> William Attwood
>> System Engineer, Co-Founder
>> Open Box I.T. Solutions, LLC
>> c. 801-634-6479
>> 
>> 
>> On Tue, Feb 5, 2013 at 2:50 PM, Joel Krauska  wrote:
>> 
>>> I know there's been some pushback about adding 'include' support in to
>>> haproxy config files.
>>> 
>>> One of the main reasons I would like that feature is to allow for more
>>> dynamic configs.
>>> 
>>> I've come to wonder if some templating/loops couldn't be built in to the
>>> haproxy config parser itself.
>>> 
>>> eg.
>>> 
>>> backend foo
>>># List of servers
>>>%
>>> for (var i=1;i<8;i++)
>>>  {server app-$i app-$1:8080 maxconn 255 weight 10}
>>>%
>>> 
>>> Any other interest in seeing this?
>>> 
>>> I imagine there are standardized approaches for doing this sort of thing.
>>> 
>>> --Joel
> 



Re: Backend Configuration Templating

2013-02-05 Thread Robin Lee Powell
This is what we do, using puppet's erb templating system:

<% haproxy_https_servers.keys.each do |server| %>
  <% haproxy_https_servers[server].each do |subserver| %>
<% extra_conditions=''
if subserver.has_key?('extra_conditions')
  extra_conditions=subserver['extra_conditions']
end %>
# content switching based on cookie, having had them set in 
previous sessions
use_backend <%= server %>-https-<%= subserver['name'] %> if { 
hdr_sub(cookie) SITE=<%= server %> } <%= extra_conditions %>
# content switching based on SNI
use_backend <%= server %>-https-<%= subserver['name'] %> if { 
ssl_fc_sni -i <%= server %> } <%= extra_conditions %>
  <% end %>
<% end %>

-Robin

On Tue, Feb 05, 2013 at 02:53:13PM -0700, William Attwood wrote:
> I would imagine you would dynamically create the haproxy configuration
> based on the sources you're using to fill your variables.  I'll be doing
> something similar, soon, where the configuration is dynamically built based
> on entries in a database.
> 
> 
> Thank you,
> William Attwood
> System Engineer, Co-Founder
> Open Box I.T. Solutions, LLC
> c. 801-634-6479
> 
> 
> On Tue, Feb 5, 2013 at 2:50 PM, Joel Krauska  wrote:
> 
> > I know there's been some pushback about adding 'include' support in to
> > haproxy config files.
> >
> > One of the main reasons I would like that feature is to allow for more
> > dynamic configs.
> >
> > I've come to wonder if some templating/loops couldn't be built in to the
> > haproxy config parser itself.
> >
> > eg.
> >
> > backend foo
> > # List of servers
> > %
> >  for (var i=1;i<8;i++)
> >   {server app-$i app-$1:8080 maxconn 255 weight 10}
> > %
> >
> > Any other interest in seeing this?
> >
> > I imagine there are standardized approaches for doing this sort of thing.
> >
> > --Joel
> >



Re: Backend Configuration Templating

2013-02-05 Thread William Attwood
I would imagine you would dynamically create the haproxy configuration
based on the sources you're using to fill your variables.  I'll be doing
something similar, soon, where the configuration is dynamically built based
on entries in a database.


Thank you,
William Attwood
System Engineer, Co-Founder
Open Box I.T. Solutions, LLC
c. 801-634-6479


On Tue, Feb 5, 2013 at 2:50 PM, Joel Krauska  wrote:

> I know there's been some pushback about adding 'include' support in to
> haproxy config files.
>
> One of the main reasons I would like that feature is to allow for more
> dynamic configs.
>
> I've come to wonder if some templating/loops couldn't be built in to the
> haproxy config parser itself.
>
> eg.
>
> backend foo
> # List of servers
> %
>  for (var i=1;i<8;i++)
>   {server app-$i app-$1:8080 maxconn 255 weight 10}
> %
>
> Any other interest in seeing this?
>
> I imagine there are standardized approaches for doing this sort of thing.
>
> --Joel
>