Skip to content

Instantly share code, notes, and snippets.

@brynary
Created December 30, 2009 07:28
Show Gist options
  • Save brynary/265900 to your computer and use it in GitHub Desktop.
Save brynary/265900 to your computer and use it in GitHub Desktop.
# Chef Client Config File
# Automatically grabs configuration from ohai ec2 metadata.
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"]
node_name o[:ec2][:instance_id]
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"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment