Skip to content

Instantly share code, notes, and snippets.

@holgr
Forked from assimovt/chef.rb
Created June 3, 2011 21:15
Show Gist options
  • Save holgr/1007180 to your computer and use it in GitHub Desktop.
Save holgr/1007180 to your computer and use it in GitHub Desktop.
Chef cookbook
# cookbooks/chef/attributes/chef.rb
set_unless[:chef][:log_location] = "STDOUT"
set_unless[:chef][:log_level] = "info"
set_unless[:chef][:url_type] = "http"
set_unless[:chef][:server_fqdn] = "your-chef-server"
set_unless[:chef][:server_port] = "4000"
set_unless[:chef][:validation_client_name] = "chef-validator"
set_unless[:chef][:cache_path] = "/var/cache/chef"
set_unless[:chef][:run_path] = "/var/run/chef"
# cookbooks/chef/recipes/client.rb
ruby_block "reload_client_config" do
block do
Chef::Config.from_file("/etc/chef/client.rb")
end
action :nothing
end
template "/etc/chef/client.rb" do
source "client.rb.erb"
owner "root"
group "root"
mode 0644
backup false
notifies :create, resources(:ruby_block => "reload_client_config")
end
file "/etc/chef/validation.pem" do
action :delete
backup false
only_if { File.size?("/etc/chef/client.pem") }
end
# cookbooks/chef/templates/default/client.rb.erb
#
# Chef Client Config File
#
# Dynamically generated by Chef - local modifications will be replaced
#
log_level :info
log_location <%= @node[:chef][:log_location] %>
ssl_verify_mode :verify_none
<% case @node[:chef][:url_type] -%>
<% when "http" -%>
chef_server_url "http://<%= @node[:chef][:server_fqdn] %>:<%= @node[:chef][:server_port] %>"
<% when "https" -%>
chef_server_url "https://<%= @node[:chef][:server_fqdn] %>"
<% end -%>
validation_client_name "<%= @node[:chef][:validation_client_name] %>"
validation_key "/etc/chef/validation.pem"
client_key "/etc/chef/client.pem"
file_cache_path "<%= @node[:chef][:cache_path] %>"
pid_file "<%= @node[:chef][:run_path] %>/client.pid"
Mixlib::Log::Formatter.show_time = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment