diff options
author | Marc A. Paradise <marc.paradise@gmail.com> | 2019-05-03 17:28:02 -0400 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2019-05-03 18:05:49 -0400 |
commit | a1c438aa2b15b310ecccd062ae714026f39d3f12 (patch) | |
tree | 8c1e21b43837d3f5dc3bfbdacc66f3caea177180 /lib | |
parent | 4dde88da4d24148987ca80b3dd7a5f802516f68d (diff) | |
download | chef-a1c438aa2b15b310ecccd062ae714026f39d3f12.tar.gz |
Pass channel directly into the script/url to determine Chef Infra downloadmp/bootstrap/restore-prerelease
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/templates/chef-full.erb | 4 | ||||
-rw-r--r-- | lib/chef/knife/core/bootstrap_context.rb | 33 | ||||
-rw-r--r-- | lib/chef/knife/core/windows_bootstrap_context.rb | 39 |
4 files changed, 17 insertions, 63 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 92f6fbcec3..5d76736e06 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -159,9 +159,9 @@ class Chef option :channel, long: "--channel CHANNEL", - description: "Install from the given channel. Valid values are 'current' and 'stable'. Default is 'stable'", + description: "Install from the given channel. Valid values are 'stable, 'current', and 'unstable'. Default is 'stable'", default: "stable", - in: %w{stable current} + in: %w{stable current unstable} # client.rb content via chef-full/bootstrap_context option :bootstrap_proxy, diff --git a/lib/chef/knife/bootstrap/templates/chef-full.erb b/lib/chef/knife/bootstrap/templates/chef-full.erb index 58a64a23b8..54fa3a61d1 100644 --- a/lib/chef/knife/bootstrap/templates/chef-full.erb +++ b/lib/chef/knife/bootstrap/templates/chef-full.erb @@ -175,9 +175,9 @@ do_download() { if test -f /usr/bin/<%= Chef::Dist::CLIENT %>}; then echo "-----> Existing <%= Chef::Dist::PRODUCT %> installation detected" else - echo "-----> Installing Chef Omnibus (<%= latest_current_chef_version_string %>)" + echo "-----> Installing Chef Omnibus (<%= @config[:channel] %>/<%= version_to_install %>)" do_download ${install_sh} $tmp_dir/install.sh - sh $tmp_dir/install.sh -P chef <%= latest_current_chef_version_string %> + sh $tmp_dir/install.sh -P chef -c <%= @config[:channel] %> -v <%= version_to_install %> fi <% end %> diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index 5889a77f25..5a27836da8 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -187,32 +187,17 @@ class Chef end # - # Determine that CLI arguments to retrieve the correct version of Chef Infra Client from omnitruck - # By default, bootstrap will look for the latest version of the currently-running major release of on stable. + # Returns the version of Chef to install (as recognized by the Omnitruck API) # - # @return [String] CLI arguments to pass into the chef download helper script - def latest_current_chef_version_string - # NOTE: Changes here should also be reflected in Knife::Core::BootstrapContext#latest_current_chef_version_string - installer_version_string = [] - use_current_channel = (@config[:channel] == "current") - installer_version_string << "-p" if use_current_channel - version = if knife_config[:bootstrap_version] - knife_config[:bootstrap_version] - else - # We will take the latest current by default, - # if no specific version is given. - if use_current_channel - # Take the latest stable version from the current major release. - # Note that if the current major release is not yet in stable, - # you must also specify channel "current". - nil - else - Chef::VERSION.split(".").first - end - end + # @return [String] download version string + def version_to_install + return knife_config[:bootstrap_version] if knife_config[:bootstrap_version] - installer_version_string.concat(["-v", version]) unless version.nil? - installer_version_string.join(" ") + if @config[:channel] == "stable" + Chef::VERSION.split(".").first + else + "latest" + end end def first_boot diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb index 42d46aa67a..109f8e6f37 100644 --- a/lib/chef/knife/core/windows_bootstrap_context.rb +++ b/lib/chef/knife/core/windows_bootstrap_context.rb @@ -158,37 +158,6 @@ class Chef start_chef << "chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json#{bootstrap_environment_option}\n" end - # - # Provide the query arguments to a URL that will be appeded to the URL in #msi_url(). This is used - # to get the latest version of Chef Infra Client via omnitruck - # By default, bootstrap will look for the latest version of the currently-running major release of on stable. - # - # @return [String] query arguments to append to the download request. - def latest_current_windows_chef_version_query - # NOTE: Changes here should also be reflected in Knife::Core::BootstrapContext#latest_current_chef_version_string - use_current_channel = (@config[:channel] == "current") - installer_version_string = use_current_channel ? "&prerelease=true" : "" - - chef_version_string = if knife_config[:bootstrap_version] - knife_config[:bootstrap_version] - else - if use_current_channel - # We will take the latest current by default, - # if no specific version is given. - nil - else - # Take the latest stable version from the current major release. - # Note that if the current major release is not yet in stable, - # you must also specify channel "current". - Chef::VERSION.split(".").first - end - end - - installer_version_string << "&v=#{chef_version_string}" if chef_version_string - - installer_version_string - end - def win_wget # I tried my best to figure out how to properly url decode and switch / to \ # but this is VBScript - so I don't really care that badly. @@ -294,16 +263,16 @@ class Chef "%TEMP%\\#{Chef::Dist::CLIENT}-latest.msi" end + # Build a URL to query www.chef.io that will redirect to the correct + # Chef Infra msi download. def msi_url(machine_os = nil, machine_arch = nil, download_context = nil) - # The default msi path has a number of url query parameters - we attempt to substitute - # such parameters in as long as they are provided by the template. - if @config[:msi_url].nil? || @config[:msi_url].empty? url = "https://www.chef.io/chef/download?p=windows" url += "&pv=#{machine_os}" unless machine_os.nil? url += "&m=#{machine_arch}" unless machine_arch.nil? url += "&DownloadContext=#{download_context}" unless download_context.nil? - url += latest_current_windows_chef_version_query + url += "&channel=#{@config[:channel]}" + url += "&v=#{version_to_install}" else @config[:msi_url] end |