Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Knife config for Multiple Chef Environments
#
# 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"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.