lib/chef/provisioning/convergence_strategy/install_sh.rb in chef-provisioning-0.19 vs lib/chef/provisioning/convergence_strategy/install_sh.rb in chef-provisioning-0.20

- old
+ new

@@ -37,16 +37,38 @@ end def setup_convergence(action_handler, machine) super - # Install chef-client. TODO check and update version if not latest / not desired - if machine.execute_always('chef-client -v').exitstatus != 0 - # TODO ssh verification of install.sh before running arbtrary code would be nice? - @@install_sh_cache[install_sh_url] ||= Net::HTTP.get(URI(install_sh_url)) - machine.write_file(action_handler, install_sh_path, @@install_sh_cache[install_sh_url], :ensure_dir => true) - machine.execute(action_handler, install_sh_command_line) + # 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 end + + # Install chef client + # TODO ssh verification of install.sh before running arbtrary code would be nice? + @@install_sh_cache[install_sh_url] ||= Net::HTTP.get(URI(install_sh_url)) + 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) end def converge(action_handler, machine) super