diff options
author | tyler-ball <tball@chef.io> | 2019-05-06 17:47:51 -0600 |
---|---|---|
committer | tyler-ball <tball@chef.io> | 2019-05-07 18:20:05 -0600 |
commit | d969482da36b9b1c3df5503ffb0d612302637a99 (patch) | |
tree | ab78a0073ad5f054eafbac482bdb1d4a2672db1b /lib/chef/knife | |
parent | 59529a0b879a86d946d07df0a648fb48014e38a4 (diff) | |
download | chef-d969482da36b9b1c3df5503ffb0d612302637a99.tar.gz |
knife bootstrap should only request license when installing Chef 15knife_license
Also updating the transmission of the license acceptance through the
config.rb because that brings it in line with existing patterns
(Test Kitchen).
Signed-off-by: tyler-ball <tball@chef.io>
Diffstat (limited to 'lib/chef/knife')
-rw-r--r-- | lib/chef/knife/bootstrap.rb | 30 | ||||
-rw-r--r-- | lib/chef/knife/core/bootstrap_context.rb | 7 | ||||
-rw-r--r-- | lib/chef/knife/core/windows_bootstrap_context.rb | 6 |
3 files changed, 32 insertions, 11 deletions
diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 90dd2417fc..6f6b31f2ec 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -398,9 +398,7 @@ class Chef on: :tail) end - attr_accessor :client_builder - attr_accessor :chef_vault_handler - attr_reader :connection + attr_reader :connection deps do require "erubis" @@ -414,20 +412,35 @@ class Chef banner "knife bootstrap [PROTOCOL://][USER@]FQDN (options)" - def initialize(argv = []) - super - LicenseAcceptance::Acceptor.check_and_persist!("infra-client", Chef::VERSION.to_s, logger: Chef::Log, provided: Chef::Config[:chef_license]) - @client_builder = Chef::Knife::Bootstrap::ClientBuilder.new( + def client_builder + @client_builder ||= Chef::Knife::Bootstrap::ClientBuilder.new( chef_config: Chef::Config, knife_config: config, ui: ui ) - @chef_vault_handler = Chef::Knife::Bootstrap::ChefVaultHandler.new( + end + + def chef_vault_handler + @chef_vault_handler ||= Chef::Knife::Bootstrap::ChefVaultHandler.new( knife_config: config, ui: ui ) end + # Determine if we need to accept the Chef Infra license locally in order to successfully bootstrap + # the remote node. Remote 'chef-client' run will fail if it is >= 15 and the license is not accepted locally. + def check_license + Chef::Log.debug("Checking if we need to accept Chef license to bootstrap node") + version = config[:bootstrap_version] || Chef::VERSION.split(".").first + acceptor = LicenseAcceptance::Acceptor.new(logger: Chef::Log, provided: Chef::Config[:chef_license]) + if acceptor.license_required?("chef", version) + Chef::Log.debug("License acceptance required for chef version: #{version}") + license_id = acceptor.id_from_mixlib("chef") + acceptor.check_and_persist(license_id, version) + Chef::Config[:chef_license] ||= acceptor.acceptance_value + end + end + # The default bootstrap template to use to bootstrap a server. # This is a public API hook which knife plugins use or inherit and override. # @@ -523,6 +536,7 @@ class Chef end def run + check_license verify_deprecated_flags! validate_name_args! diff --git a/lib/chef/knife/core/bootstrap_context.rb b/lib/chef/knife/core/bootstrap_context.rb index f9ebf52b31..3dccb048ec 100644 --- a/lib/chef/knife/core/bootstrap_context.rb +++ b/lib/chef/knife/core/bootstrap_context.rb @@ -92,6 +92,10 @@ class Chef validation_client_name "#{@chef_config[:validation_client_name]}" CONFIG + unless @chef_config[:chef_license].nil? + client_rb << "chef_license \"#{@chef_config[:chef_license]}\"" + end + if !(@chef_config[:config_log_level].nil? || @chef_config[:config_log_level].empty?) client_rb << %Q{log_level :#{@chef_config[:config_log_level]}\n} end @@ -171,8 +175,7 @@ class Chef def start_chef # If the user doesn't have a client path configure, let bash use the PATH for what it was designed for client_path = @chef_config[:chef_client_path] || "#{Chef::Dist::CLIENT}" - # We know we can hardcode CHEF_LICENSE because the user cannot get here without accepting the license locally - s = "CHEF_LICENSE=accept #{client_path} -j /etc/chef/first-boot.json" + s = "#{client_path} -j /etc/chef/first-boot.json" if @config[:verbosity] && @config[:verbosity] >= 3 s << " -l trace" elsif @config[:verbosity] && @config[:verbosity] >= 2 diff --git a/lib/chef/knife/core/windows_bootstrap_context.rb b/lib/chef/knife/core/windows_bootstrap_context.rb index 109f8e6f37..a1b7311f51 100644 --- a/lib/chef/knife/core/windows_bootstrap_context.rb +++ b/lib/chef/knife/core/windows_bootstrap_context.rb @@ -63,6 +63,11 @@ class Chef file_backup_path "c:/chef/backup" cache_options ({:path => "c:/chef/cache/checksums", :skip_expires => true}) CONFIG + + unless @chef_config[:chef_license].nil? + client_rb << "chef_license \"#{@chef_config[:chef_license]}\"" + end + if @config[:chef_node_name] client_rb << %Q{node_name "#{@config[:chef_node_name]}"\n} else @@ -154,7 +159,6 @@ class Chef def start_chef bootstrap_environment_option = bootstrap_environment.nil? ? "" : " -E #{bootstrap_environment}" start_chef = "SET \"PATH=%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\System32\\Wbem;%SYSTEMROOT%\\System32\\WindowsPowerShell\\v1.0\\;C:\\ruby\\bin;C:\\opscode\\chef\\bin;C:\\opscode\\chef\\embedded\\bin\"\n" - start_chef << "SET \"CHEF_LICENSE=accept\"\n" start_chef << "chef-client -c c:/chef/client.rb -j c:/chef/first-boot.json#{bootstrap_environment_option}\n" end |