diff options
Diffstat (limited to 'lib/puppet/application')
-rw-r--r-- | lib/puppet/application/puppet.rb | 50 |
1 files changed, 42 insertions, 8 deletions
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 |