diff options
author | Luke Kanies <luke@madstop.com> | 2009-08-01 12:45:55 -0700 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-08-02 17:37:27 +1000 |
commit | 7e5b56212eef22be381a480dcaf38b33620674dd (patch) | |
tree | 1315c26a67e3d84f87830dacab726ea30ce818af /lib/puppet | |
parent | 97274ad976e3584ae850ad91cc886fae1dcdbbc6 (diff) | |
download | puppet-7e5b56212eef22be381a480dcaf38b33620674dd.tar.gz puppet-7e5b56212eef22be381a480dcaf38b33620674dd.tar.xz puppet-7e5b56212eef22be381a480dcaf38b33620674dd.zip |
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 <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/application/puppet.rb | 50 | ||||
-rw-r--r-- | lib/puppet/configurer.rb | 4 |
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 |