Created
November 8, 2012 20:56
-
-
Save mriddle/4041536 to your computer and use it in GitHub Desktop.
Basic knife configuration for chef server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Chef Knife config example | |
# https://github.com/fnichol/chef-bootstrap-repo/blob/master/.chef/knife.rb | |
### | |
# Environment variables required: | |
# CHEF_SERVER_URL - IP or url of your chef server | |
# CHEF_USER - Initial user | |
# AWS_ACCESS_KEY - AWS Access ID found here https://portal.aws.amazon.com/gp/aws/securityCredentials | |
# AWS_SECRET_KEY - AWS Secrete key found in link above | |
current_dir = File.dirname(__FILE__) | |
home_dir = ENV['HOME'] | |
chef_dir = "#{home_dir}/.chef" | |
chefd_dir = "#{home_dir}/projects/lpos-chef-repo/.chef" | |
user = ENV['CHEF_USER'] | |
server_url = "http://#{ENV['CHEF_SERVER_URL']}:4000" | |
# path to cookbooks | |
cookbook_path ["#{current_dir}/../cookbooks", | |
"#{current_dir}/../site-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 | |
validation_client_name "chef-validator" | |
client_key "#{chefd_dir}/#{user}-client.pem" | |
validation_key "#{chefd_dir}/validation.pem" | |
chef_server_url "#{server_url}" | |
# caching options | |
cache_type 'BasicFile' | |
cache_options( :path => "#{home_dir}/.chef/checksums" ) | |
file_backup_path "#{chef_dir}/backups" | |
# 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" | |
knife[:aws_access_key_id] = ENV['AWS_ACCESS_KEY'] | |
knife[:aws_secret_access_key] = ENV['AWS_SECRET_KEY'] | |
# aws ec2 configuration | |
if ENV['AWS_ACCESS_KEY'] && ENV['AWS_SECRET_KEY'] | |
## | |
# Searches the ENV hash for keys starting with "AWS_" and converts them | |
# to knife config settings. For example: | |
# | |
# ENV['AWS_AWS_ACCESS_KEY_ID'] = "abcabc" | |
# ENV['AWS_FLAVOR'] = "t1.small" | |
# | |
# becomes: | |
# | |
# knife[:aws_access_key_id] = "abcabc" | |
# knife[:flavor] = "t1.small" | |
aws_attrs = ENV.keys.select { |k| k =~ /^AWS_/ } | |
aws_attrs.each do |key| | |
knife.send(:[]=, key.sub(/^AWS_/, '').downcase.to_sym, ENV[key]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment