diff --git a/kitchen-tests/cookbooks/end_to_end/recipes/_chef_client_config.rb b/kitchen-tests/cookbooks/end_to_end/recipes/_chef_client_config.rb index c2a6e4254b4..31dac49fc65 100644 --- a/kitchen-tests/cookbooks/end_to_end/recipes/_chef_client_config.rb +++ b/kitchen-tests/cookbooks/end_to_end/recipes/_chef_client_config.rb @@ -1,5 +1,6 @@ chef_client_config "Create chef-client's client.rb" do chef_server_url "https://localhost" + log_location windows? ? "C:\\chef\\log_test\\client.log" : "/var/log/chef/log_test/client.log" chef_license "accept" ohai_optional_plugins %i{Passwd Lspci Sysctl} ohai_disabled_plugins %i{Sessions Interrupts} diff --git a/lib/chef/resource/chef_client_config.rb b/lib/chef/resource/chef_client_config.rb index df97d7cc2f4..e02010a147f 100644 --- a/lib/chef/resource/chef_client_config.rb +++ b/lib/chef/resource/chef_client_config.rb @@ -249,21 +249,20 @@ def string_to_symbol(prop_val) description: "The data collector token to interact with the data collector server URL (Automate). Note: If possible, use Chef Infra Server to do all data collection reporting, as this removes the need to distribute tokens to individual nodes.", introduced: "17.8" - action :create, description: "Create a client.rb config file for configuring #{ChefUtils::Dist::Infra::PRODUCT}." do - unless ::Dir.exist?(new_resource.config_directory) - directory new_resource.config_directory do + action :create, description: "Create a client.rb config file and folders for configuring #{ChefUtils::Dist::Infra::PRODUCT}." do + [ + new_resource.config_directory, + (::File.dirname(new_resource.log_location) unless new_resource.log_location.nil?), + new_resource.file_backup_path, + new_resource.file_cache_path, + ::File.join(new_resource.config_directory, "client.d"), + (::File.dirname(new_resource.pid_file) unless new_resource.pid_file.nil?), + ].compact.each do |dir_path| + + directory dir_path do user new_resource.user unless new_resource.user.nil? group new_resource.group unless new_resource.group.nil? - mode "0750" - recursive true - end - end - - unless ::Dir.exist?(::File.join(new_resource.config_directory, "client.d")) - directory ::File.join(new_resource.config_directory, "client.d") do - user new_resource.user unless new_resource.user.nil? - group new_resource.group unless new_resource.group.nil? - mode "0750" + mode dir_path == ::File.dirname(new_resource.log_location) ? "0755" : "0750" recursive true end end