diff --git a/plugins/provisioners/chef/config/base_runner.rb b/plugins/provisioners/chef/config/base_runner.rb index df0329589..cfee8e76e 100644 --- a/plugins/provisioners/chef/config/base_runner.rb +++ b/plugins/provisioners/chef/config/base_runner.rb @@ -83,9 +83,9 @@ module VagrantPlugins @https_proxy_pass = nil if @https_proxy_pass == UNSET_VALUE @no_proxy = nil if @no_proxy == UNSET_VALUE @node_name = nil if @node_name == UNSET_VALUE - @provisioning_path = "/tmp/vagrant-chef" if @provisioning_path == UNSET_VALUE - @file_backup_path = "/var/chef/backup" if @file_backup_path == UNSET_VALUE - @file_cache_path = "/var/chef/cache" if @file_cache_path == UNSET_VALUE + @provisioning_path = nil if @provisioning_path == UNSET_VALUE + @file_backup_path = nil if @file_backup_path == UNSET_VALUE + @file_cache_path = nil if @file_cache_path == UNSET_VALUE @verbose_logging = false if @verbose_logging == UNSET_VALUE @enable_reporting = true if @enable_reporting == UNSET_VALUE diff --git a/plugins/provisioners/chef/config/chef_client.rb b/plugins/provisioners/chef/config/chef_client.rb index 7d4f4d27a..331cc9b21 100644 --- a/plugins/provisioners/chef/config/chef_client.rb +++ b/plugins/provisioners/chef/config/chef_client.rb @@ -45,7 +45,7 @@ module VagrantPlugins super @chef_server_url = nil if @chef_server_url == UNSET_VALUE - @client_key_path = "/etc/chef/client.pem" if @client_key_path == UNSET_VALUE + @client_key_path = nil if @client_key_path == UNSET_VALUE @delete_client = false if @delete_client == UNSET_VALUE @delete_node = false if @delete_node == UNSET_VALUE @validation_client_name = "chef-validator" if @validation_client_name == UNSET_VALUE diff --git a/plugins/provisioners/chef/provisioner/base.rb b/plugins/provisioners/chef/provisioner/base.rb index 2de3d28cf..726b93078 100644 --- a/plugins/provisioners/chef/provisioner/base.rb +++ b/plugins/provisioners/chef/provisioner/base.rb @@ -66,9 +66,11 @@ module VagrantPlugins end def chown_provisioning_folder - paths = [@config.provisioning_path, - @config.file_backup_path, - @config.file_cache_path] + paths = [ + guest_provisioning_path, + guest_file_backup_path, + guest_file_cache_path, + ] @machine.communicate.tap do |comm| paths.each do |path| @@ -89,7 +91,7 @@ module VagrantPlugins expanded = File.expand_path( @config.custom_config_path, @machine.env.root_path) remote_custom_config_path = File.join( - config.provisioning_path, "custom-config.rb") + guest_provisioning_path, "custom-config.rb") @machine.communicate.upload(expanded, remote_custom_config_path) end @@ -98,8 +100,8 @@ module VagrantPlugins custom_configuration: remote_custom_config_path, encrypted_data_bag_secret: guest_encrypted_data_bag_secret_key_path, environment: @config.environment, - file_cache_path: @config.file_cache_path, - file_backup_path: @config.file_backup_path, + file_cache_path: guest_file_cache_path, + file_backup_path: guest_file_backup_path, log_level: @config.log_level.to_sym, node_name: @config.node_name, verbose_logging: @config.verbose_logging, @@ -120,7 +122,7 @@ module VagrantPlugins temp.write(config_file) temp.close - remote_file = File.join(config.provisioning_path, filename) + remote_file = File.join(guest_provisioning_path, filename) @machine.communicate.tap do |comm| comm.sudo("rm -f #{remote_file}", error_check: false) comm.upload(temp.path, remote_file) @@ -142,7 +144,7 @@ module VagrantPlugins temp.write(json) temp.close - remote_file = File.join(@config.provisioning_path, "dna.json") + remote_file = File.join(guest_provisioning_path, "dna.json") @machine.communicate.tap do |comm| if windows? command = "if (test-path '#{remote_file}') {rm '#{remote_file}' -force -recurse}" @@ -194,7 +196,43 @@ module VagrantPlugins def guest_encrypted_data_bag_secret_key_path if @config.encrypted_data_bag_secret_key_path - File.join(@config.provisioning_path, "encrypted_data_bag_secret_key") + File.join(guest_provisioning_path, "encrypted_data_bag_secret_key") + end + end + + def guest_provisioning_path + if !@config.provisioning_path.nil? + return @config.provisioning_path + end + + if windows? + "C:/vagrant-chef" + else + "/tmp/vagrant-chef" + end + end + + def guest_file_backup_path + if !@config.file_backup_path.nil? + return @config.file_backup_path + end + + if windows? + "C:/chef/backup" + else + "/var/chef/backup" + end + end + + def guest_file_cache_path + if !@config.file_cache_path.nil? + return @config.file_cache_path + end + + if windows? + "C:/chef/cache" + else + "/var/chef/cache" end end diff --git a/plugins/provisioners/chef/provisioner/chef_client.rb b/plugins/provisioners/chef/provisioner/chef_client.rb index 58e665499..f2751eb68 100644 --- a/plugins/provisioners/chef/provisioner/chef_client.rb +++ b/plugins/provisioners/chef/provisioner/chef_client.rb @@ -37,7 +37,7 @@ module VagrantPlugins def create_client_key_folder @machine.ui.info I18n.t("vagrant.provisioners.chef.client_key_folder") - path = Pathname.new(@config.client_key_path) + path = Pathname.new(guest_client_key_path) if windows? @machine.communicate.sudo("mkdir ""#{path.dirname}"" -f") @@ -56,7 +56,7 @@ module VagrantPlugins chef_server_url: @config.chef_server_url, validation_client_name: @config.validation_client_name, validation_key: guest_validation_key_path, - client_key: @config.client_key_path, + client_key: guest_client_key_path, }) end @@ -101,8 +101,20 @@ module VagrantPlugins File.expand_path(@config.validation_key_path, @machine.env.root_path) end + def guest_client_key_path + if !@config.client_key_path.nil? + return @config.client_key_path + end + + if windows? + "C:/chef/client.pem" + else + "/etc/chef/client.pem" + end + end + def guest_validation_key_path - File.join(@config.provisioning_path, "validation.pem") + File.join(guest_provisioning_path, "validation.pem") end def delete_from_chef_server(deletable) diff --git a/plugins/provisioners/chef/provisioner/chef_solo.rb b/plugins/provisioners/chef/provisioner/chef_solo.rb index 8f38ad424..c21811e9e 100644 --- a/plugins/provisioners/chef/provisioner/chef_solo.rb +++ b/plugins/provisioners/chef/provisioner/chef_solo.rb @@ -82,7 +82,7 @@ module VagrantPlugins # Path exists on the host, setup the remote path. We use # the MD5 of the local path so that it is predictable. key = Digest::MD5.hexdigest(local_path) - remote_path = "#{@config.provisioning_path}/#{key}" + remote_path = "#{guest_provisioning_path}/#{key}" else @machine.ui.warn(I18n.t("vagrant.provisioners.chef.cookbook_folder_not_found_warning", path: local_path.to_s)) @@ -91,7 +91,7 @@ module VagrantPlugins else # Path already exists on the virtual machine. Expand it # relative to where we're provisioning. - remote_path = File.expand_path(path, @config.provisioning_path) + remote_path = File.expand_path(path, guest_provisioning_path) # Remove drive letter if running on a windows host. This is a bit # of a hack but is the most portable way I can think of at the moment diff --git a/plugins/provisioners/chef/provisioner/chef_zero.rb b/plugins/provisioners/chef/provisioner/chef_zero.rb index 53b5096ee..1e5f61766 100644 --- a/plugins/provisioners/chef/provisioner/chef_zero.rb +++ b/plugins/provisioners/chef/provisioner/chef_zero.rb @@ -82,7 +82,7 @@ module VagrantPlugins # Path exists on the host, setup the remote path. We use # the MD5 of the local path so that it is predictable. key = Digest::MD5.hexdigest(local_path) - remote_path = "#{@config.provisioning_path}/#{key}" + remote_path = "#{guest_provisioning_path}/#{key}" else @machine.ui.warn(I18n.t( "vagrant.provisioners.chef.cookbook_folder_not_found_warning", @@ -92,7 +92,7 @@ module VagrantPlugins else # Path already exists on the virtual machine. Expand it # relative to where we're provisioning. - remote_path = File.expand_path(path, @config.provisioning_path) + remote_path = File.expand_path(path, guest_provisioning_path) # Remove drive letter if running on a windows host. This is a bit # of a hack but is the most portable way I can think of at the moment diff --git a/test/unit/plugins/provisioners/chef/config/base_runner_test.rb b/test/unit/plugins/provisioners/chef/config/base_runner_test.rb index 3ef7e2fab..8bc6c6402 100644 --- a/test/unit/plugins/provisioners/chef/config/base_runner_test.rb +++ b/test/unit/plugins/provisioners/chef/config/base_runner_test.rb @@ -121,23 +121,23 @@ describe VagrantPlugins::Chef::Config::BaseRunner do end describe "#provisioning_path" do - it "defaults to a tmp_path" do + it "defaults to nil" do subject.finalize! - expect(subject.provisioning_path).to eq("/tmp/vagrant-chef") + expect(subject.provisioning_path).to be(nil) end end describe "#file_backup_path" do - it "defaults to /var/chef/backup" do + it "defaults to nil" do subject.finalize! - expect(subject.file_backup_path).to eq("/var/chef/backup") + expect(subject.file_backup_path).to be(nil) end end describe "#file_cache_path" do - it "defaults to /var/chef/cache" do + it "defaults to nil" do subject.finalize! - expect(subject.file_cache_path).to eq("/var/chef/cache") + expect(subject.file_cache_path).to be(nil) end end diff --git a/test/unit/plugins/provisioners/chef/config/chef_client_test.rb b/test/unit/plugins/provisioners/chef/config/chef_client_test.rb index 17f2dc321..25034d019 100644 --- a/test/unit/plugins/provisioners/chef/config/chef_client_test.rb +++ b/test/unit/plugins/provisioners/chef/config/chef_client_test.rb @@ -17,9 +17,9 @@ describe VagrantPlugins::Chef::Config::ChefClient do end describe "#client_key_path" do - it "defaults to /etc/chef/client.pem" do + it "defaults to nil" do subject.finalize! - expect(subject.client_key_path).to eq("/etc/chef/client.pem") + expect(subject.client_key_path).to be(nil) end end