summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/application/puppet.rb50
-rw-r--r--lib/puppet/configurer.rb4
2 files changed, 45 insertions, 9 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
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