Last active
March 13, 2019 17:06
-
-
Save reidmv/3e7fa02be3c0475bd830e4eb0dfb4087 to your computer and use it in GitHub Desktop.
Catalog terminus to inject node data
This file contains 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
# 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 |
This file contains 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
# 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 |
This file contains 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
# 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