# File lib/puppet/indirector/node/exec.rb, line 9 def command command = Puppet[:external_nodes] raise ArgumentError, "You must set the 'external_nodes' parameter to use the external node terminus" unless command != "none" command.split end
Look for external node definitions.
# File lib/puppet/indirector/node/exec.rb, line 16 def find(request) output = super or return nil # Translate the output to ruby. result = translate(request.key, output) # Set the requested environment if it wasn't overridden # If we don't do this it gets set to the local default result[:environment] ||= request.environment.name create_node(request.key, result) end
Turn our outputted objects into a Puppet::Node instance.
# File lib/puppet/indirector/node/exec.rb, line 37 def create_node(name, result) node = Puppet::Node.new(name) set = false [:parameters, :classes, :environment].each do |param| if value = result[param] node.send(param.to_s + "=", value) set = true end end node.fact_merge node end
Proxy the execution, so it’s easier to test.
# File lib/puppet/indirector/node/exec.rb, line 32 def execute(command, arguments) Puppet::Util::Execution.execute(command,arguments) end
Translate the yaml string into Ruby objects.
# File lib/puppet/indirector/node/exec.rb, line 52 def translate(name, output) YAML.load(output).inject({}) do |hash, data| case data[0] when String hash[data[0].intern] = data[1] when Symbol hash[data[0]] = data[1] else raise Puppet::Error, "key is a #{data[0].class}, not a string or symbol" end hash end rescue => detail raise Puppet::Error, "Could not load external node results for #{name}: #{detail}" end