Ask Your Question
1

How do you reconcile puppetlabs-haproxy and consul-template?

asked 2016-05-05 19:01:17 -0500

haloflightleader gravatar image

I am using puppetlabs-haproxy and need to use consul-template. As you know, puppetlabs-haproxy can create the configuration for you. However, I also need consul-template to change that configuration. How do you reconcile them?

I don't want to completely unmanage from puppet the haproxy configuration because if I have something new, it's fill-in-the-blanks easy in the manifest for frontends -- including ports (I wrote a function that generates a port based on the hash of the service name -- so it's really easy).

In order for consul-template to work, I need to completely unmanage haproxy.cfg from puppet which means defining new frontends lose their fill-in-the-blanks ease. Thanks for your help in advance.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2016-05-09 09:01:34 -0500

garethr gravatar image

Hi. I wrote the example linked to above :)

You have a few options. The example linked https://github.com/puppetlabs/puppet-... doesn't use consul template, but achieves the same results using Consul and Puppet alone. That's one approach.

If you do want to use consul-template for the reactive changes then you can do that do. The important part is to make sure the relevant information is all in Consul. You can then use the consul-hiera backend to get that information when running Puppet, or access the same information using consul-template. You end up with a little duplication in the template mind, but not a great deal.

edit flag offensive delete link more

Comments

1

I think your example works, but the config will be updated only on puppet runs. I don't want to tie together the config management and service discovery because then the config management becomes THE service discovery. But this is a creative approach.

haloflightleader gravatar imagehaloflightleader ( 2016-05-09 19:23:37 -0500 )edit

The first examples does only run when puppet runs, but puppet runs whenever a new service is discovered or removed. Consul is doing the service discovery in that case, Puppet is simply reacting to that discovery and updating files.

garethr gravatar imagegarethr ( 2016-05-11 02:53:50 -0500 )edit
1

The second option uses consul-template and Puppet to update the same file, just on a different cadence. This is safe to do if both get the information from consul. In Puppet's case via the consul-hiera backend.

garethr gravatar imagegarethr ( 2016-05-11 02:54:45 -0500 )edit
1

I must have missed that second option. I'm going to look again. Thanks a bunch.

haloflightleader gravatar imagehaloflightleader ( 2016-05-11 12:10:54 -0500 )edit
0

answered 2016-05-06 21:02:26 -0500

DarylW gravatar image

updated 2016-05-06 21:15:31 -0500

Your best bet would be to manage the values that are stored in consul with puppet, and allow consul-template to update the config file. I haven't had a chance to play with consul-template yet to understand what tempting you have available to you, but it seems like that would be the best way to handle it. Otherwise you get 'thrashing' between what consul-template thinks the file should be and what puppet thinks it should be. I don't know if it is possible to have multiple config files (similar to a conf.d directory). If that's the case, you would be able to manage different services with different files.. one with puppet, one with consul.

Let us know if you come up with anything.. I'll try playing with both this weekend and see if I can figure anything out!

--- EDIT ---

I found another question hereat ask.puppet.com, and stumbled on this demo project. They use a consul watcher to trigger a puppet run. That gives you puppet managing the file, but consul managing the services discovery component.

https://github.com/puppetlabs/puppet-...

edit flag offensive delete link more
0

answered 2016-05-09 19:28:46 -0500

haloflightleader gravatar image

I can think of only one way to do this, it's really a poor compromise. I'm just going to create a separate module that manages the haproxy.cfg (reinventing the wheel and it's going to be square). But instead of writing the balance members, I'm just going to write in the templating syntax of consul-template. And then I'll configure through puppet consul-template to populate that haproxy.cfg in the right place and the rest is really up to consul-template.

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

2 followers

Stats

Asked: 2016-05-05 19:01:17 -0500

Seen: 152 times

Last updated: May 09 '16