Skip to content

Instantly share code, notes, and snippets.

@adamhjk
Created October 28, 2009 20:56
Show Gist options
  • Save adamhjk/220828 to your computer and use it in GitHub Desktop.
Save adamhjk/220828 to your computer and use it in GitHub Desktop.
# Chef Client Config File
require 'ohai'
require 'json'
o = Ohai::System.new
o.all_plugins
chef_config = JSON.parse(o[:ec2][:userdata])
if chef_config.kind_of?(Array)
chef_config = chef_config[o[:ec2][:ami_launch_index]]
end
log_level :info
log_location STDOUT
chef_server_url chef_config["chef_server"]
registration_url chef_config["chef_server"]
openid_url chef_config["chef_server"]
template_url chef_config["chef_server"]
remotefile_url chef_config["chef_server"]
search_url chef_config["chef_server"]
role_url chef_config["chef_server"]
client_url chef_config["chef_server"]
unless File.exists?("/etc/chef/client.pem")
File.open("/etc/chef/validation.pem", "w") do |f|
f.print(chef_config["validation_key"])
end
end
if chef_config.has_key?("attributes")
File.open("/etc/chef/client-config.json", "w") do |f|
f.print(JSON.pretty_generate(chef_config["attributes"]))
end
json_attribs "/etc/chef/client-config.json"
end
validation_key "/etc/chef/validation.pem"
validation_client_name chef_config["validation_client_name"]
Chef::Log::Formatter.show_time = true
{
"validation_key": "... redacted ...",
"attributes": {
"run_list": [
"role[monkey]"
]
},
"chef_server": "https:\/\/api.opscode.com\/organizations\/opscode",
"validation_client_name": "opscode-validator"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment