lib/chef/knife/solo_cook.rb in knife-solo-0.1.0.pre1 vs lib/chef/knife/solo_cook.rb in knife-solo-0.1.0

- old
+ new

@@ -8,50 +8,50 @@ class Chef class Knife # Approach ported from spatula (https://github.com/trotter/spatula) # Copyright 2009, Trotter Cashion class SoloCook < Knife - OMNIBUS_EMBEDDED_PATHS ||= ["/opt/chef/embedded/bin", "/opt/opscode/embedded/bin"] - OMNIBUS_EMBEDDED_GEM_PATHS ||= ["/opt/chef/embedded/lib/ruby/gems/1.9.1", "/opt/opscode/embedded/lib/ruby/gems/1.9.1"] + OMNIBUS_EMBEDDED_PATHS ||= %w[/opt/chef/embedded/bin /opt/opscode/embedded/bin] + OMNIBUS_EMBEDDED_GEM_PATHS ||= %w[/opt/chef/embedded/lib/ruby/gems/1.9.1 /opt/opscode/embedded/lib/ruby/gems/1.9.1] CHEF_VERSION_CONSTRAINT ||= ">=0.10.4" include KnifeSolo::SshCommand include KnifeSolo::KitchenCommand include KnifeSolo::NodeConfigCommand include KnifeSolo::Tools deps do require 'chef/cookbook/chefignore' + require 'librarian/action' + require 'librarian/chef' require 'pathname' KnifeSolo::SshCommand.load_deps KnifeSolo::NodeConfigCommand.load_deps end banner "knife solo cook [USER@]HOSTNAME [JSON] (options)" option :skip_chef_check, - :long => '--skip-chef-check', - :boolean => true, - :description => "Skip the version check on the Chef gem" + :long => '--skip-chef-check', + :description => 'Skip the version check on the Chef gem' option :sync_only, - :long => '--sync-only', - :boolean => false, - :description => "Only sync the cookbook - do not run Chef" + :long => '--sync-only', + :description => 'Only sync the cookbook - do not run Chef' option :why_run, - :short => '-W', - :long => '--why-run', - :boolean => true, - :description => "Enable whyrun mode" + :short => '-W', + :long => '--why-run', + :description => 'Enable whyrun mode' def run time('Run') do validate! Chef::Config.from_file('solo.rb') check_chef_version unless config[:skip_chef_check] generate_node_config + librarian_install rsync_kitchen add_patches cook unless config[:sync_only] end end @@ -92,9 +92,20 @@ return yield unless debug? ui.msg "Starting '#{msg}'" start = Time.now yield ui.msg "#{msg} finished in #{Time.now - start} seconds" + end + + def librarian_install + return unless File.exist? 'Cheffile' + Chef::Log.debug("Installing Librarian cookbooks") + Librarian::Action::Resolve.new(librarian_env).run + Librarian::Action::Install.new(librarian_env).run + end + + def librarian_env + @librarian_env ||= Librarian::Chef::Environment.new end def rsync_kitchen time('Rsync kitchen') do cmd = %Q{rsync -rl --rsh="ssh #{ssh_args}" --delete #{rsync_exclude.collect{ |ignore| "--exclude #{ignore} " }.join} ./ :#{adjust_rsync_path(chef_path)}}