Ask Your Question

How to lookup for other puppet nodes dynamically using module name etc.?

asked 2015-08-07 03:38:50 -0600

Mr_Sharma gravatar image

Hi, I am quite new to Puppet though I know chef well. I want to setup a webserver load balancer on multiple nodes. For this I need to collect info on node A(webserver) about other nodes say B, C and D(tomcat clients) where module tomcat has already been executed.

Can I have lookup inside my manifest about other nodes via module name?

I don't want to use Hiera because It doesn't look like a dynamic lookup. I just don't wanna put data into some yaml files everytime after code execution. Please help.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-08-10 03:31:40 -0600

garethr gravatar image

Hi Rajeev

There are a few ways of doing this in Puppet, depending on your usecase.

One approach is called exported resources. In this module B, C and D would export a resource and those resources would be collected (and realised) on A.

A more direct approach, and probably one more familiar to you if you used Chef search, is puppetdbquery. This allows A to query puppetdb for all tomcat clients, which should return B, C and D (and later more tomcat nodes as you add them).

A quick side-note. Hiera is really just the interface. Yes, you may have static data in YAML files or whatnot, but hiera also supports other backends - for instance puppetdbquery above or something like consul.

The last example uses the hiera-consul backend, along with the approved consul puppet module. It's a bit more involved than just using puppetdbquery but has some other nice properties like being really fast to update when nodes are added/removed.

edit flag offensive delete link more


Hi Garethr, Thanks. Quite an explained and detailed answer. I will try this and will get back.

Mr_Sharma gravatar imageMr_Sharma ( 2015-08-10 05:59:43 -0600 )edit

Can you please give me an example in contrast of search() in chef. I need to know following: - lookup string - store returned values in a variable - use that variable in the code ahead e.g. templates I am not able to find out great usage of collectors. Please help.

Mr_Sharma gravatar imageMr_Sharma ( 2015-08-12 05:11:29 -0600 )edit

Hi garethr, I was off the track so couldn't tried this out at that very time. Today I tried this and it's working fine. Earlier only issue I was facing where to place the export and collector resources in the code(being a naive user). Anyways thanks for the pointer.

Mr_Sharma gravatar imageMr_Sharma ( 2016-02-17 06:49:40 -0600 )edit

answered 2015-08-19 13:44:42 -0600

Hi Rajeev,

I'd recommend the exported resources method mentioned by @garethr. I'll try to use an example for Haproxy balancermembers, which is very simple. Firstly you'll need PuppetDB setup with the Puppet Master.

On node B,C,D You'll export the resource that you want to generate using data available at that time on that node:

@@haproxy::balancermember { "haproxy-${title}-${::fqdn}":
      listening_service => 'myhaproxybackend',
      server_names      => "${::hostname}_${title}",
      ipaddresses       => $::ipaddress,
      ports             => $https_port,
      options           => [
        'verify none']

Then, on Node A (which would be the server actually running Haproxy in this example) you'll collect the exported resources. The puppetlabs haproxy module actually collects by default, but in this example you'd do:

Haproxy::Balancermember <<| |>>

We use this exact model for tomcat instances, and HaProxy load balancer and it works brilliantly. The only thing to watch for is balancermember config hanging around due to a long default TTL on the exported resources in PuppetDB.

HTH, Josh

edit flag offensive delete link more


Hi Josh, Can you please explain how does this work? Haproxy::Balancermember <<| |>> and how can we collect all ipadresses into an array from all exported resources? e.g. in chef we do: clusteripaddress = search('ipaddress', 'recipe::tomcat') I am looking for such kind of function. Thanks.

Mr_Sharma gravatar imageMr_Sharma ( 2015-09-10 02:42:02 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-08-07 03:38:50 -0600

Seen: 860 times

Last updated: Aug 19 '15