Build nginx conf dynamically (depending on the upstream machines)

590 views
Skip to first unread message

Gonçalo

unread,
May 26, 2010, 8:03:22 AM5/26/10
to Puppet Users
Hi there, im trying to set up puppet to manage a nginx server with
load balancing. To achieve this i need to add every machine ip to the
"upstream" conf of nginx. Doing this manually is easy, and all works
fine, the problem is that i would like to have every upstream machine
to "warn" the nginx to add that machine ip to the conf. This way i
would not need to change the conf manually everytime i add/remove a
machine.
To solve this problem i only found one solution (untested yet), that
would be have every upstream machine use Exported Resources to create
a file with its ip:port on a folder on the nginx server, and then have
a batch program creating the nginx conf, based on those files...
Is there any elegant way to do this?
I already posted this question on server fault (http://serverfault.com/
questions/145244/load-balancing-with-puppet), and at that time i was
thinking of just write an include directive inside the upstream on the
conf, but that is not accepted by nginx, so i only have the option
above left..and the one someone can possibly say here :-)
Thanks

David Schmitt

unread,
May 26, 2010, 8:34:36 AM5/26/10
to puppet...@googlegroups.com

Hi,

as I've answered on SF, I'd recommend [R.I.Pienaar's concat][1] module.
With this you can export/collect configuration file snippets and
concatenate them on the target into a single file.

Best Regards, David

[1]: http://github.com/ripienaar/puppet-concat
--
dasz.at OG Tel: +43 (0)664 2602670 Web: http://dasz.at
Klosterneuburg UID: ATU64260999

FB-Nr.: FN 309285 g FB-Gericht: LG Korneuburg

Gonçalo Queirós

unread,
May 26, 2010, 2:18:24 PM5/26/10
to puppet...@googlegroups.com
Thank you David.
That module helped me implement one of the proposed solutions. I though
there might be something "prettier" to handle this kind of situations,
but seems not.
Thanks for your module :-)

Daniel Pittman

unread,
May 26, 2010, 11:10:13 PM5/26/10
to puppet...@googlegroups.com
Gonçalo Queirós <goncalo...@gmail.com> writes:

> That module helped me implement one of the proposed solutions. I though
> there might be something "prettier" to handle this kind of situations,
> but seems not.

Nope. That is the "best practice" mechanism for doing this. Sorry.

Daniel

--
✣ Daniel Pittman ✉ dan...@rimspace.net+61 401 155 707
♽ made with 100 percent post-consumer electrons

David Schmitt

unread,
May 28, 2010, 12:25:21 PM5/28/10
to puppet...@googlegroups.com
On 27.05.2010 05:10, Daniel Pittman wrote:
> Gonçalo Queirós<goncalo...@gmail.com> writes:
>
>> That module helped me implement one of the proposed solutions. I though
>> there might be something "prettier" to handle this kind of situations,
>> but seems not.
>
> Nope. That is the "best practice" mechanism for doing this. Sorry.

Not quite. Best practice would be to implement a native type which
parses out the config file, but that involves ruby.


Best Regards, David

Nicolas Szalay

unread,
Jun 1, 2010, 9:20:51 AM6/1/10
to puppet...@googlegroups.com
Le mercredi 26 mai 2010 à 05:03 -0700, Gonçalo a écrit :

Hello Gonçalo

I do this with templates with embedded ruby. This is not the best
practice, it's pretty far away from it.

Your solution with exported resources is almost the same, except the
fact you're using file (when I'm using a database)

The only problem I see is when you have multiple upstream : how will you
know in which upstream you want a server to be ?

Regarding the concat module I don't see how to use it for this because
some "calculations" have to be made.

To me the only "quick" solution is a template embedding ruby, and the
only "clean" solution is a native type (longer to do/test/maintain) as
David suggests.

My 2c

Nico.

signature.asc
Reply all
Reply to author
Forward
0 new messages