Skip to content

Instantly share code, notes, and snippets.

@ticean
Forked from fnichol/knife.rb
Created October 21, 2011 07:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ticean/1303291 to your computer and use it in GitHub Desktop.
Save ticean/1303291 to your computer and use it in GitHub Desktop.
My Generic 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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment