From 8661a43800e6c47fd9f5184dbf1d565590739e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sat, 24 Oct 2026 15:29:07 +0200 Subject: [PATCH] Support Cinc in kosmos-base Resolve the client config dir at runtime (Chef::Config[:config_file] / :client_d_dir) instead of hardcoding /etc/chef, and create client.d when missing so fresh nodes work. Reload only the attributes file we just wrote, not the whole client.rb: reloading client.rb reset chef_server_url and dropped knife-zero's -S (TCP) override, so later server calls fell back to socketless chefzero and failed with No socketless Cinc Zero server. --- site-cookbooks/kosmos-base/recipes/default.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos-base/recipes/default.rb b/site-cookbooks/kosmos-base/recipes/default.rb index 40bbac8..21a44cb 100644 --- a/site-cookbooks/kosmos-base/recipes/default.rb +++ b/site-cookbooks/kosmos-base/recipes/default.rb @@ -3,9 +3,19 @@ # Recipe:: default # +# Resolve the client's own config paths so this works for both Chef (/etc/chef) +# and Cinc (/etc/cinc) rather than hardcoding /etc/chef. +config_file = Chef::Config[:config_file] +client_d_dir = Chef::Config[:client_d_dir] + +directory client_d_dir do + recursive true + mode "0755" +end + ruby_block "cleanup client.rb" do block do - fe = Chef::Util::FileEdit.new("/etc/chef/client.rb") + fe = Chef::Util::FileEdit.new(config_file) # Delete whitelist attribute definitions, everything is defined in attributes.rb fe.search_file_delete_line(/^.*_attribute_whitelist.*/) fe.search_file_delete_line(/^allowed_.*_attributes.*/) @@ -13,7 +23,7 @@ ruby_block "cleanup client.rb" do end end -cookbook_file "/etc/chef/client.d/attributes.rb" do +cookbook_file "#{client_d_dir}/attributes.rb" do source "chef_attributes.rb" mode "0644" notifies :create, "ruby_block[reload_client_config]", :immediately @@ -21,7 +31,10 @@ end ruby_block "reload_client_config" do block do - Chef::Config.from_file("/etc/chef/client.rb") + # Reload only the attribute-persistence config we just wrote. Reloading the + # whole client.rb would reset chef_server_url and break knife-zero's -S + # (TCP) override, making server calls fall back to socketless chefzero. + Chef::Config.from_file("#{client_d_dir}/attributes.rb") end action :nothing end