Skip to content

Instantly share code, notes, and snippets.

@hunner
Last active December 12, 2015 12:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hunner/4773601 to your computer and use it in GitHub Desktop.
Hiera node terminus
## lib/puppet/indirector/node/hiera.rb
require 'puppet/node'
require 'puppet/indirector/code'
require 'hiera'
class Puppet::Node::Hiera < Puppet::Indirector::Code
desc 'Return a collection of classes and parameters by querying hiera for "classes" and "parameters" data entries.'
def find(request)
facts = Puppet::Node::Facts.indirection.find(request.key)
hiera = Hiera.new(:config => {:logger => 'puppet'})
environment = hiera.lookup('hiera::environment', {}, facts.values, nil, :priority)
node = Puppet::Node.new(
request.key,
:environment => environment,
:parameters => hiera.lookup('hiera::parameters', {:environment => environment}, facts.values, nil, :hash),
:classes => hiera.lookup('classes', {:environment => environment}, facts.values, nil, :hash)
)
node
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment