Created
December 26, 2013 18:59
-
-
Save reidmv/8137423 to your computer and use it in GitHub Desktop.
Custom Facts indirector to inject extra Hiera-based fact
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'puppet/indirector/facts/puppetdb' | |
require 'puppet/node/facts' | |
require 'hiera' | |
class Puppet::Node::Facts::PuppetdbWithNetwork < Puppet::Node::Facts::Puppetdb | |
# Here we override the normal save, injecting a custom fact | |
def save(args) | |
name = args.instance.name | |
facts = args.instance.values | |
facts.define_singleton_method(:lookupvar) do |key| | |
self[key] || self[key.to_s] | |
end | |
begin | |
config = Hiera::Config.load(Puppet['hiera_config']) | |
config[:logger] = 'puppet' | |
hiera = Hiera.new(:config => config) | |
# For any Hiera lookup to inject as a fact, add it here | |
network = hiera.lookup('network', nil, facts, nil, :priority) | |
facts['network'] = network if network | |
args.instance = Puppet::Node::Facts.new(name, facts) | |
rescue | |
# ignore | |
ensure | |
super(args) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment