summaryrefslogtreecommitdiff
path: root/lib/chef/knife
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-08-22 11:34:34 -0700
committerSerdar Sutay <serdar@opscode.com>2014-08-26 15:42:27 -0700
commitc79ceca006bb18b59489ac077879710711bdfd99 (patch)
treeec6e99faa9acea4993af70dee4813aa74a9230f2 /lib/chef/knife
parentb03b2aa547e6c9766d9ed39e29351540209c7b06 (diff)
downloadchef-c79ceca006bb18b59489ac077879710711bdfd99.tar.gz
Specs for bootstrap cleanup.
Diffstat (limited to 'lib/chef/knife')
-rw-r--r--lib/chef/knife/bootstrap.rb23
-rw-r--r--lib/chef/knife/core/bootstrap_context.rb10
2 files changed, 15 insertions, 18 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb
index 4440443821..6d98a70b9b 100644
--- a/lib/chef/knife/bootstrap.rb
+++ b/lib/chef/knife/bootstrap.rb
@@ -194,15 +194,14 @@ class Chef
# Use the template directly if it's a path to an actual file
if File.exists?(template)
- Chef::Log.debug("Using the specified bootstrap template: #{File.dirname(bootstrap_template)}")
+ Chef::Log.debug("Using the specified bootstrap template: #{File.dirname(template)}")
return template
end
# Otherwise search the template directories until we find the right one
-
bootstrap_files = []
bootstrap_files << File.join(File.dirname(__FILE__), 'bootstrap', "#{template}.erb")
- bootstrap_files << File.join(Knife.chef_config_dir, "bootstrap", "#{template}.erb") if Knife.chef_config_dir
+ bootstrap_files << File.join(Knife.chef_config_dir, "bootstrap", "#{template}.erb") if Chef::Knife.chef_config_dir
bootstrap_files << File.join(ENV['HOME'], '.chef', 'bootstrap', "#{template}.erb") if ENV['HOME']
bootstrap_files << Gem.find_files(File.join("chef","knife","bootstrap","#{template}.erb"))
bootstrap_files.flatten!
@@ -213,33 +212,27 @@ class Chef
end
unless template_file
- ui.info("Can not find bootstrap definition for #{config[:template]}")
+ ui.info("Can not find bootstrap definition for #{template}")
raise Errno::ENOENT
end
- Chef::Log.debug("Found bootstrap template in #{File.dirname(template)}")
+ Chef::Log.debug("Found bootstrap template in #{File.dirname(template_file)}")
template_file
end
- def render_template(template=nil)
+ def render_template
+ template_file = find_template
+ template = IO.read(template_file).chomp
context = Knife::Core::BootstrapContext.new(config, config[:run_list], Chef::Config)
Erubis::Eruby.new(template).evaluate(context)
end
- def read_template
- IO.read(@template_file).chomp
- end
-
def run
validate_name_args!
- @template_file = find_template
@node_name = Array(@name_args).first
- # back compat--templates may use this setting:
- config[:server_name] = @node_name
$stdout.sync = true
-
ui.info("Connecting to #{ui.color(@node_name, :bold)}")
begin
@@ -291,7 +284,7 @@ class Chef
end
def ssh_command
- command = render_template(read_template)
+ command = render_template
if config[:use_sudo]
command = config[:use_sudo_password] ? "echo '#{config[:ssh_password]}' | sudo -S #{command}" : "sudo #{command}"
diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb
index 4583766bf3..0fdd77594a 100644
--- a/lib/chef/knife/core/bootstrap_context.rb
+++ b/lib/chef/knife/core/bootstrap_context.rb
@@ -99,11 +99,15 @@ CONFIG
# X here can be 10 or 11
def latest_current_chef_version_string
installer_version_string = nil
- if config[:prerelease]
+ if @config[:prerelease]
installer_version_string = "-p"
else
- Chef::VERSION.split(".").first
- end
+ chef_version_string = if knife_config[:bootstrap_version]
+ knife_config[:bootstrap_version]
+ else
+ Chef::VERSION.split(".").first
+ end
+
installer_version_string = ["-v", chef_version_string]
# If bootstrapping a pre-release version add -p to the installer string