Ask Your Question

Best method to get external data source into Puppet

asked 2013-04-19 03:11:01 -0500

maxwell gravatar image

We need to query an external database that is the authoritative data source for one of our modules. The options we have come up with so far are:

  1. Create a custom function in lib/puppet/parser/functions that queries the external database and returns the data. One concern with this method is what will happen if the datasource is not available.
  2. Query the database from within the erb template within a block of ruby code. This doesn't feel right and would result in more connections than necessary as the module has around 10 templates.
  3. Create a custom ENC script ...
edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2013-04-19 04:21:56 -0500

jonn gravatar image

A custom rvalue function would be the usual way to achieve this. As it's ruby, you can write it to do whatever you like if the datasource isn't around (return some emergency defaults, raise an exception, etc)

You could use the built-in rvalue function generate() to call the database via a script. If it fails, it will raise a Puppet::ParseError exception.

There's also hiera-mysql which might be an interesting starting point if you want to try and build out some infrastructure for this type of thing.

edit flag offensive delete link more


hiera-mysql is what I was going to recommend, although I've never used it myself. I just really like the idea of having one hierarchy of data lookups, with different backends.

Ancillas gravatar imageAncillas ( 2013-04-19 09:18:15 -0500 )edit

thanks @jonn! We're looking into hiera-mysql. Do you know what would happen if the rvalue function did raise an exception?

maxwell gravatar imagemaxwell ( 2013-04-20 05:06:49 -0500 )edit

Hi @maxwell - it should just propagate the exception up to Puppet, which will fail the catalog.

jonn gravatar imagejonn ( 2013-04-20 08:31:32 -0500 )edit

answered 2013-05-09 23:53:29 -0500

John mentioned generate(), I had never used it (Thx John) but played a little with it as it is quite interesting, for a quick and simple integration with external tools:

class common {
  $my_external_var = generate('/usr/bin/pwgen', '-1')
  notice("My external var --> $my_external_var") }

Running it :

$ puppet apply manifests/site.pp --modulepath=modules
notice: Scope(Class[Common]): My external var --> phahthoh

notice: Finished catalog run in 0.03 seconds

I might use that to get the exact build metadata from Jenkins and use it to get the precise package version that was pushed to our repository.

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



Asked: 2013-04-19 03:11:01 -0500

Seen: 825 times

Last updated: May 09 '13