1

I am working on making our puppet infrastructure more dynamic where I can add any number of nodes and these will automatically be applied in another nodes configuration.

An example: I have X number of hosts running a Java application, which are defined by our javaapp module with the following define in it (simplified):

define javaapp::site (
  $site_name,
  $site_port ) {
  # Doing some stuff regarding deployment, service management etc here
}

These are defined in the site.pp file like this:

javaapp::site { 'app01':
  play_site_name    => 'app01',
  play_site_port    => 9100,
}

We have a nginx reverse proxy in front of these application servers where I need to forward requests to a range of servers. Currently my nginx template looks like this:

upstream app-hosts {
  server <%= @host_app_01 %>:9100;
  server <%= @host_app_02 %>:9100;
}

Where @host_app_01 and @host_app_02 have been defined globally in the site.pp file

What I would like to do is to collect an array of the nodes with a specific javaapp site name and use it in the nginx template. Something like this pseudo-code:

upstream app-hosts {
  <% @host_app.each do |host| %>
    server <%= @host.ip %>:<%= @host.appPort %>;
  <% end %>
}

I have read a little about exported resources, but I can't figure out whether it is the right thing for this situation?

Is it even possible to do with puppet?

We are running puppet version 3.7.5.

1 Answer 1

1

Exported resources are a very adequate design pattern for this, yes. However, a template cannot directly use the resources (imported or otherwise) from the current catalog.

Your best call will be one of the concat modules. Have your defined types export concat snippets for your applications. Instead of a file that uses a template for its content, use a concat resource.

1
  • 1
    Thanks for pointing me to the concat modules - didn't realize that was an option until now. I also noticed that jfryman's nginx module actually supports exported resources, so maybe I should just go with that in the future when I finish converting my sites to his module
    – Frederik
    Jan 19, 2016 at 9:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .