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.