lib/chef/knife/cook.rb in knife-solo-0.0.12 vs lib/chef/knife/cook.rb in knife-solo-0.0.13
- old
+ new
@@ -18,10 +18,12 @@
include KnifeSolo::SshCommand
include KnifeSolo::KitchenCommand
include KnifeSolo::Tools
+ class WrongCookError < KnifeSolo::KnifeSoloError; end
+
banner "knife cook [user@]hostname [json] (options)"
option :skip_chef_check,
:long => '--skip-chef-check',
:boolean => true,
@@ -35,13 +37,20 @@
option :skip_syntax_check,
:long => '--skip-syntax-check',
:boolean => true,
:description => "Skip Ruby syntax checks"
+ option :syntax_check_only,
+ :long => '--syntax-check-only',
+ :boolean => true,
+ :description => "Only run syntax checks - do not run Chef"
+
def run
+ validate_params!
super
check_syntax unless config[:skip_syntax_check]
+ return if config[:syntax_check_only]
Chef::Config.from_file('solo.rb')
check_chef_version unless config[:skip_chef_check]
rsync_kitchen
add_patches
cook unless config[:sync_only]
@@ -61,10 +70,11 @@
JSON.parse File.read(json), :create_additions => false
rescue => error
raise "Syntax error in #{json}: #{error.message}"
end
end
+ Chef::Log.info "cookbook and json syntax is ok"
end
def node_config
@name_args[1] || super
end
@@ -107,18 +117,23 @@
export PATH="#{OMNIBUS_EMBEDDED_PATHS.join(":")}:$PATH"
ruby -rubygems -e "gem 'chef', '#{CHEF_VERSION_CONSTRAINT}'"
BASH
raise "Couldn't find Chef #{CHEF_VERSION_CONSTRAINT} on #{host}. Please run `#{$0} prepare #{ssh_args}` to ensure Chef is installed and up to date." unless result.success?
end
-
+
def cook
logging_arg = "-l debug" if config[:verbosity] > 0
stream_command <<-BASH
sudo chef-solo -c #{chef_path}/solo.rb \
-j #{chef_path}/#{node_config} \
#{logging_arg}
BASH
end
+
+ def validate_params!
+ validate_first_cli_arg_is_a_hostname!(WrongCookError)
+ end
+
end
end
end