Skip to content

Instantly share code, notes, and snippets.

@danielsdeleo
Forked from jtimberman/ec2_client.rb
Created June 23, 2010 23:44
Show Gist options
  • Save danielsdeleo/450746 to your computer and use it in GitHub Desktop.
Save danielsdeleo/450746 to your computer and use it in GitHub Desktop.
# Author:: Adam Jacob <[email protected]>
# Author:: Joshua Timberman <[email protected]>
#
# Copyright 2009-2010, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Chef Client Config File: /etc/chef/client.rb
# Automatically grabs configuration from ohai ec2 metadata.
#
# Also note: sets the node's name to the EC2 instance ID, recommended as
# hostnames, fqdn's and IPs can be recycled.
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
node_name o[:ec2][:instance_id]
chef_server_url chef_config["chef_server"]
unless File.exists?("/etc/chef/client.pem")
File.open("/etc/chef/validation.pem", "w", 0600) do |f|
f.print(chef_config["validation_key"])
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
end
validation_key "/etc/chef/validation.pem"
validation_client_name chef_config["validation_client_name"]
Mixlib::Log::Formatter.show_time = true
{
"validation_key": "-----BEGIN RSA PRIVATE KEY-----\nsomelongreallyawesomekey\n-----END RSA PRIVATE KEY-----\n",
"attributes": {
"run_list": [
"role[base]"
]
},
"chef_server": "http://chef.example.com:4000",
"validation_client_name": "chef-validator"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment