Skip to content

Instantly share code, notes, and snippets.

@fnichol
Created September 17, 2011 19:26
Show Gist options
  • Save fnichol/1224263 to your computer and use it in GitHub Desktop.
Save fnichol/1224263 to your computer and use it in GitHub Desktop.
My Generic Chef knife.rb
### Chef Solo
#
#
### Opscode Hosted Chef Server
#
# export KNIFE_USER="jdoe"
# export KNIFE_ORGNAME="acmeco"
#
# * Your Opscode client key should be at `~/.chef.d/opscode-jdoe.pem`.
# * Your Opscode validation key should be at `~/.chef.d/opscode-acmeco-validator.pem`.
#
### Chef Server
#
# export KNIFE_USER="hsolo"
# export KNIFE_SERVER_NAME="widgetinc"
# export KNIFE_SERVER_URL="https://chef.widgetinc.com"
#
# * Your Chef Server client key should be at `~/.chef.d/widgetinc-hsolo.pem`.
# * Your Chef Server validation key should be at `~/.chef.d/widgetinc-validator.pem`.
#
current_dir = File.dirname(__FILE__)
home_dir = ENV['HOME']
chef_dir = "#{home_dir}/.chef.d"
user = ENV['KNIFE_USER'] || ENV['USER']
orgname = ENV['KNIFE_ORGNAME']
server_name = ENV['KNIFE_SERVER_NAME']
server_url = ENV['KNIFE_SERVER_URL']
# path to cookbooks
cookbook_path ["#{current_dir}/../cookbooks"]
# logging details
log_level :info
log_location STDOUT
# user/client and private key to authenticate to a Chef Server, if needed
node_name user
if orgname
# if KNIFE_ORGNAME is given, then we're talking to the Opscode Hosted Chef
# Server
validation_client_name "#{orgname}-validator"
client_key "#{chef_dir}/opscode-#{user}.pem"
validation_key "#{chef_dir}/opscode-#{orgname}-validator.pem"
chef_server_url "https://api.opscode.com/organizations/#{orgname}"
elsif server_name
# if KNIFE_SERVER_NAME is defined, then we're talking to a Chef Server
validation_client_name "#{server_name}-validator"
client_key "#{chef_dir}/#{server_name}-#{user}.pem"
validation_key "#{chef_dir}/#{server_name}-validator.pem"
chef_server_url server_url
end
# caching options
cache_type 'BasicFile'
cache_options( :path => "#{home_dir}/.chef/checksums" )
# new cookbook defaults
cookbook_copyright ENV['KNIFE_COOKBOOK_COPYRIGHT'] ||
%x{git config --get user.name}.chomp
cookbook_email ENV['KNIFE_COOKBOOK_EMAIL'] ||
%x{git config --get user.email}.chomp
cookbook_license "apachev2"
# rackspace configuration
if ENV['RACKSPACE_USERNAME'] && ENV['RACKSPACE_API_KEY']
knife[:rackspace_api_username] = ENV['RACKSPACE_USERNAME']
knife[:rackspace_api_key] = ENV['RACKSPACE_API_KEY']
end
# aws ec2 configuration
if ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY']
knife[:aws_access_key_id] = ENV['AWS_ACCESS_KEY_ID']
knife[:aws_secret_access_key] = ENV['AWS_SECRET_ACCESS_KEY']
end
# linode configuration
if ENV['LINODE_API_KEY']
knife[:linode_api_key] = ENV['LINODE_API_KEY']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment