Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chef_client_config: ensure config property directories exist #12416

Merged
merged 12 commits into from Jan 14, 2022
@@ -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}
Expand Down
25 changes: 13 additions & 12 deletions lib/chef/resource/chef_client_config.rb
Expand Up @@ -250,20 +250,21 @@ def string_to_symbol(prop_val)
introduced: "17.8"

action :create, description: "Create a client.rb config file for configuring #{ChefUtils::Dist::Infra::PRODUCT}." do
Stromweld marked this conversation as resolved.
Show resolved Hide resolved
unless ::Dir.exist?(new_resource.config_directory)
directory new_resource.config_directory 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?),
].each do |dir_path|
next if dir_path.nil?
next if ::Dir.exist?(dir_path)
Stromweld marked this conversation as resolved.
Show resolved Hide resolved

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"
Stromweld marked this conversation as resolved.
Show resolved Hide resolved
recursive true
end
end
Expand Down