Skip to content

Instantly share code, notes, and snippets.

@reidmv
Last active March 13, 2019 17:06
Show Gist options
  • Save reidmv/3e7fa02be3c0475bd830e4eb0dfb4087 to your computer and use it in GitHub Desktop.
Save reidmv/3e7fa02be3c0475bd830e4eb0dfb4087 to your computer and use it in GitHub Desktop.
Catalog terminus to inject node data
# Example catalog terminus
require 'puppet/indirector/catalog/compiler'
class Puppet::Resource::Catalog::CompilerFactmerge < Puppet::Resource::Catalog::Compiler
def find(request)
if request.options[:use_node]
request.options[:use_node].add_extra_facts(node_data)
else
facts = extract_facts_from_request(request)
facts.add_extra_values(node_data)
request.options[:facts] = Puppet::Util.uri_query_encode(facts.render('json'))
request.options[:facts_format] = 'application/json'
end
super(request)
end
def node_data
data = {}
# This is where the API call should be made to retrieve the data
data['test'] = 'example'
{'node_data' => data}
end
end
# Example custom fact
Facter.add(:node_data) do
setcode do
data = {}
# This is where the API call should be made to retrieve the data
# Should use Puppet agent's certificate for auth/identity
data['test'] = 'example'
data
end
end
# Config required in the master's puppet.conf to use catalog terminus
[master]
catalog_terminus = compiler_factmerge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment