Created
February 18, 2012 19:06
-
-
Save kevinkarwaski/1860681 to your computer and use it in GitHub Desktop.
Knife config for Multiple Chef Environments
This file contains hidden or 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
# | |
# This is an example of a knife.rb configuration that uses yml and a | |
# simple env var (CHEF_ENV) to manage multiple hosted Chef environments. | |
# | |
# Example usage: | |
# export CHEF_ENV=evnironment_01 | |
# knife status | |
# | |
# Based on: http://blog.blankpad.net/2010/09/28/multiple-knife-environments---the-return/ | |
# | |
# The directory structure will look something like this: | |
# .chef/ | |
# ├── environment_01 | |
# │ ├── checksums | |
# │ ├── config.yml | |
# │ ├── environment_01-validator.pem | |
# │ └── user.pem | |
# ├── environment_02 | |
# | ├── checksums | |
# │ ├── config.yml | |
# │ ├── environment_02-validator.pem | |
# │ └── user.pem | |
# └── knife.rb | |
# Example environment_01 config.yml: | |
node_name: "user" | |
server: "https://api.opscode.com/organizations/environment_01" | |
validator: "environment_01-validator" | |
# Example knife.rb file parses the config.yml based on the value of CHEF_ENV: | |
require 'yaml' | |
CHEF_ENV = ENV['CHEF_ENV'] || "your_environment" | |
current_dir = File.dirname(__FILE__) | |
env_config = YAML.load_file("#{current_dir}/#{CHEF_ENV}/config.yml") | |
log_level :info | |
log_location STDOUT | |
node_name env_config["node_name"] | |
client_key "#{current_dir}/#{CHEF_ENV}/#{env_config["node_name"]}.pem" | |
validation_client_name env_config["validator"] || "chef-validator" | |
validation_key "#{current_dir}/#{env_config["validator"]}.pem" | |
chef_server_url env_config["server"] | |
cache_type 'BasicFile' | |
cache_options( :path => "#{current_dir}/#{CHEF_ENV}/checksums" ) | |
cookbook_path ["#{current_dir}/../chef-repo/cookbooks", "#{current_dir}/../chef-repo/site-cookbooks"] | |
Worked like a charm here, thank you very much!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great solution