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.
This commit is contained in:
raucao committed 2026-10-24 15:29:07 +02:00
1 parent ab9a55fd06
commit 8661a43800
1 file changed
+16 -3
+16 -3
View File
@@ -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