Experiment for querying data out of storedconfigs
Ruby Puppet
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


LICENSE: Apache v2

AUTHOR: Dan Bode

This is currently a prototype.


This module provides facilities for searching for a list of nodes using
facts and classes contained in the last compiled catalag as filters.


This code will only work against Puppet 2.7.3 or higher.

It requires that storedconfigs is enabled. For more information about
configuring storedconfigs, look here:


This has only been tested against mysql as the backend for storedconfigs.


command line:

To use puppet hostclass from the command line, you will have to
add the lib directory of this module to your RUBYLIB env variabe.

  export RUBYLIB=/etc/puppet/modules/puppetlabs-nodesearch/lib:$RUBYLIB

  # returns a list of nodes whose last compiled catalog contains
  # the classes foo, bar, AND baz
  puppet hostclass search --classes foo,bar,baz

As a puppet function:

from within Puppet, you can invoke the function search_nodes

search nodes allows you to specify both facts as well as classes to
use as a filter for searching nodes.

If you intend to use facts as filters, then you will need to set inventory_active_record
as the facts terminus in puppet.conf (as as an option to puppet).


The functions search_nodes takes a hash as the only parameter.

The hash can have either keys prefixed with facts. or a key called classes which
expects an array.

Examples of usage:

The following example shows how the function could be used to grant access to a database
to only nodes that have been assigned a specific class.

node db::server {
  class { 'db::server':
    # authorize clients that use the class db::client
    allowed_clients => search_nodes({classes => ['db::client']}),

Full examples have been provided in the examples directory:

Below is the main section from puppet.conf that I used for testing:

    storeconfigs = true
    dbadapter = mysql
    dbname = puppet
    dbserver = localhost
    dbuser = root
    dbpassword = password
    dbsocket = /var/lib/mysql/mysql.sock