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