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

Reply via email to