lib/chef/provisioning/convergence_strategy/install_sh.rb in chef-provisioning-1.2.1 vs lib/chef/provisioning/convergence_strategy/install_sh.rb in chef-provisioning-1.3.0
- old
+ new
@@ -1,7 +1,8 @@
require 'chef/provisioning/convergence_strategy/precreate_chef_objects'
require 'pathname'
+require 'mixlib/install'
class Chef
module Provisioning
class ConvergenceStrategy
class InstallSh < PrecreateChefObjects
@@ -27,61 +28,22 @@
attr_reader :install_sh_url
attr_reader :install_sh_path
attr_reader :install_sh_arguments
attr_reader :bootstrap_env
- def install_sh_command_line
- arguments = install_sh_arguments ? " #{install_sh_arguments}" : ""
- arguments << " -v #{chef_version}" if chef_version
- arguments << " -p" if prerelease
- "bash -c '#{bootstrap_env} bash #{install_sh_path}#{arguments}'"
- end
-
def setup_convergence(action_handler, machine)
super
- # Check for existing chef client.
- version = machine.execute_always('chef-client -v')
-
- # Don't do install/upgrade if a chef client exists and
- # no chef version is defined by user configs or
- # the chef client's version already matches user config
- if version.exitstatus == 0
- version = version.stdout.strip
- if !chef_version
- return
- # This logic doesn't cover the case for a client with 12.0.1.dev.0 => 12.0.1
- # so we decided to just use exact version for the time being (see comments in PR 303)
- #elsif version.stdout.strip =~ /Chef: #{chef_version}([^0-9]|$)/
- elsif version =~ /Chef: #{chef_version}$/
- Chef::Log.debug "Already installed chef version #{version}"
- return
- elsif version.include?(chef_version)
- Chef::Log.warn "Installed chef version #{version} contains desired version #{chef_version}. " +
- "If you see this message on consecutive chef runs tighten your desired version constraint to prevent " +
- "multiple convergence."
- end
+ opts = {"prerelease" => prerelease}
+ if convergence_options[:bootstrap_proxy]
+ opts["http_proxy"] = convergence_options[:bootstrap_proxy]
+ opts["https_proxy"] = convergence_options[:bootstrap_proxy]
end
- # Install chef client
- # TODO ssh verification of install.sh before running arbtrary code would be nice?
- if !convergence_options[:bootstrap_proxy] || convergence_options[:bootstrap_proxy].empty?
- @@install_sh_cache[install_sh_url] ||= Net::HTTP.get(URI(install_sh_url))
- else
- @@install_sh_cache[install_sh_url] ||= begin
- proxy_uri = URI.parse(convergence_options[:bootstrap_proxy])
- chef_uri = URI.parse(@install_sh_url)
- proxy = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
- req = Net::HTTP::Get.new(chef_uri.path)
- script = proxy.start(chef_uri.host, :use_ssl => proxy_uri.scheme == 'https') do |http|
- http.request(req)
- end
- script.body
- end
- end
- machine.write_file(action_handler, install_sh_path, @@install_sh_cache[install_sh_url], :ensure_dir => true)
- # TODO handle bad version case better
- machine.execute(action_handler, install_sh_command_line)
+ install_command = Mixlib::Install.new(chef_version, false, opts).install_command
+ machine.write_file(action_handler, install_sh_path, install_command, :ensure_dir => true)
+ machine.set_attributes(action_handler, install_sh_path, :mode => '0755')
+ machine.execute(action_handler, "sh -c #{install_sh_path}")
end
def converge(action_handler, machine)
super