From 7e5b56212eef22be381a480dcaf38b33620674dd Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sat, 1 Aug 2009 12:45:55 -0700 Subject: Adding #2477 - puppet can apply provided catalogs This provides the other half of #2440 - you can compile catalogs into json with puppetmasterd, and now you can take those json catalogs and apply them. This allows you to use whatever mechanism you want to ship the catalogs around. Signed-off-by: Luke Kanies --- lib/puppet/application/puppet.rb | 50 +++++++++++++++++++++++++++++++++------- lib/puppet/configurer.rb | 4 +++- 2 files changed, 45 insertions(+), 9 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/puppet.rb b/lib/puppet/application/puppet.rb index ee848a503..dd752846c 100644 --- a/lib/puppet/application/puppet.rb +++ b/lib/puppet/application/puppet.rb @@ -16,6 +16,10 @@ Puppet::Application.new(:puppet) do option("--use-nodes") option("--detailed-exitcodes") + option("--apply catalog", "-a catalog") do |arg| + options[:catalog] = arg + end + option("--logdest LOGDEST", "-l") do |arg| begin Puppet::Util::Log.newdestination(arg) @@ -26,7 +30,37 @@ Puppet::Application.new(:puppet) do end dispatch do - return Puppet[:parseonly] ? :parseonly : :main + if options[:catalog] + :apply + elsif Puppet[:parseonly] + :parseonly + else + :main + end + end + + command(:apply) do + require 'puppet/configurer' + + if options[:catalog] == "-" + text = $stdin.read + else + text = File.read(options[:catalog]) + end + + begin + catalog = JSON.parse(text) + unless catalog.is_a?(Puppet::Resource::Catalog) + catalog = Puppet::Resource::Catalog.json_create(catalog) + end + rescue => detail + raise Puppet::Error, "Could not deserialize catalog from json: %s" % detail + end + + catalog = catalog.to_ral + + configurer = Puppet::Configurer.new + configurer.run :catalog => catalog end command(:parseonly) do @@ -40,6 +74,13 @@ Puppet::Application.new(:puppet) do end command(:main) do + # Set our code or file to use. + if options[:code] or ARGV.length == 0 + Puppet[:code] = options[:code] || STDIN.read + else + Puppet[:manifest] = ARGV.shift + end + # Collect our facts. facts = Puppet::Node::Facts.find(Puppet[:certname]) @@ -126,12 +167,5 @@ Puppet::Application.new(:puppet) do elsif options[:verbose] Puppet::Util::Log.level = :info end - - # Set our code or file to use. - if options[:code] or ARGV.length == 0 - Puppet[:code] = options[:code] || STDIN.read - else - Puppet[:manifest] = ARGV.shift - end end end diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index 8ec0b0055..81845f5cf 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -130,7 +130,9 @@ class Puppet::Configurer def run(options = {}) prepare() - unless catalog = retrieve_catalog + if catalog = options[:catalog] + options.delete(:catalog) + elsif ! catalog = retrieve_catalog Puppet.err "Could not retrieve catalog; skipping run" return end -- cgit