lib/chef/knife/solo_cook.rb in knife-solo-0.4.3 vs lib/chef/knife/solo_cook.rb in knife-solo-0.5.0
- old
+ new
@@ -24,11 +24,11 @@
require 'pathname'
KnifeSolo::SshCommand.load_deps
KnifeSolo::NodeConfigCommand.load_deps
end
- banner "knife solo cook [USER@]HOSTNAME [JSON] (options)"
+ banner "knife solo cook [USER@]HOSTNAME [JSONFILE] (options)"
option :chef_check,
:long => '--no-chef-check',
:description => 'Skip the Chef version check on the node',
:default => true
@@ -51,10 +51,14 @@
option :librarian,
:long => '--no-librarian',
:description => 'Skip librarian-chef install'
+ option :secret_file,
+ :long => '--secret-file SECRET_FILE',
+ :description => 'A file containing the secret key used to encrypt data bag item values'
+
option :why_run,
:short => '-W',
:long => '--why-run',
:description => 'Enable whyrun mode'
@@ -121,11 +125,11 @@
end
upload_to_provision_path(node_config.to_s, 'dna.json')
upload_to_provision_path(nodes_path, 'nodes')
upload_to_provision_path(:role_path, 'roles')
upload_to_provision_path(:data_bag_path, 'data_bags')
- upload_to_provision_path(:encrypted_data_bag_secret, 'data_bag_key')
+ upload_to_provision_path(config[:secret_file] || :encrypted_data_bag_secret, 'data_bag_key')
upload_to_provision_path(:environment_path, 'environments')
end
def ssl_verify_mode
Chef::Config[:ssl_verify_mode] || :verify_peer
@@ -142,11 +146,11 @@
def cookbook_paths
@cookbook_paths ||= expanded_config_paths(:cookbook_path)
end
def proxy_setting_keys
- [:http_proxy, :https_proxy, :http_proxy_user, :http_proxy_pass, :no_proxy]
+ [:http_proxy, :https_proxy, :http_proxy_user, :http_proxy_pass, :https_proxy_user, :https_proxy_pass, :no_proxy]
end
def proxy_settings
proxy_setting_keys.inject(Hash.new) do |ret, key|
ret[key] = Chef::Config[key] if Chef::Config[key]
@@ -165,24 +169,24 @@
def chefignore
@chefignore ||= ::Chef::Cookbook::Chefignore.new("./")
end
- # cygwin rsync path must be adjusted to work
- def adjust_rsync_path(path)
+ # path must be adjusted to work on windows
+ def adjust_rsync_path(path, path_prefix)
path_s = path.to_s
- path_s.gsub(/^(\w):/) { "/cygdrive/#{$1}" }
+ path_s.gsub(/^(\w):/) { path_prefix + "/#{$1}" }
end
def adjust_rsync_path_on_node(path)
return path unless windows_node?
- adjust_rsync_path(path)
+ adjust_rsync_path(path, config_value(:cygdrive_prefix_remote, '/cygdrive'))
end
def adjust_rsync_path_on_client(path)
return path unless windows_client?
- adjust_rsync_path(path)
+ adjust_rsync_path(path, config_value(:cygdrive_prefix_local, '/cygdrive'))
end
def rsync_debug
'-v' if debug?
end
@@ -191,11 +195,11 @@
def rsync_permissions
'--chmod=ugo=rwX' if windows_client?
end
def rsync_excludes
- (%w{revision-deploys tmp .git .hg .svn .bzr} + chefignore.ignores).uniq
+ (%w{revision-deploys .git .hg .svn .bzr} + chefignore.ignores).uniq
end
def debug?
config[:verbosity] and config[:verbosity] > 0
end
@@ -254,22 +258,25 @@
upload(file.path, dest)
ensure
file.unlink
end
- def rsync(source_path, target_path, extra_opts = '--delete-after')
+ def rsync(source_path, target_path, extra_opts = ['--delete-after', '-zt'])
if config[:ssh_gateway]
ssh_command = "ssh -TA #{config[:ssh_gateway]} ssh -T -o StrictHostKeyChecking=no #{ssh_args}"
else
ssh_command = "ssh #{ssh_args}"
end
- cmd = ['rsync', '-rL', rsync_debug, rsync_permissions, %Q{--rsh=#{ssh_command}}, extra_opts]
+ cmd = ['rsync', '-rL', rsync_debug, rsync_permissions, %Q{--rsh=#{ssh_command}}]
+ cmd += extra_opts
cmd += rsync_excludes.map { |ignore| "--exclude=#{ignore}" }
- cmd << adjust_rsync_path_on_client(source_path)
- cmd << %Q{:#{adjust_rsync_path_on_node(target_path)}}
- cmd = cmd.flatten.compact
+ cmd += [ adjust_rsync_path_on_client(source_path),
+ ':' + adjust_rsync_path_on_node(target_path) ]
+
+ cmd = cmd.compact
+
Chef::Log.debug cmd.inspect
system!(*cmd)
end
def check_chef_version
@@ -294,15 +301,16 @@
run_command(cmd).stdout.strip
end.call
end
def cook
- ui.msg "Running Chef..."
cmd = "sudo chef-solo -c #{provisioning_path}/solo.rb -j #{provisioning_path}/dna.json"
cmd << " -l debug" if debug?
cmd << " -N #{config[:chef_node_name]}" if config[:chef_node_name]
cmd << " -W" if config[:why_run]
cmd << " -o #{config[:override_runlist]}" if config[:override_runlist]
+
+ ui.msg "Running Chef: #{cmd}"
result = stream_command cmd
raise "chef-solo failed. See output above." unless result.success?
end