Created
February 24, 2011 17:23
-
-
Save rmoriz/842491 to your computer and use it in GitHub Desktop.
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
# FIRST: Environment variables | |
knife_env = ENV['KNIFE_ENV'] | |
knife_org = ENV['KNIFE_ORG'] | |
knife_config_dir = ENV['KNIFE_CONFIG_DIR'] | |
knife_config_file = ENV['KNIFE_CONFIG_FILE'] | |
if knife_env.blank? | |
`git branch 2> /dev/null` =~ /^\*\s(.*)$/ | |
git_branch = $1 | |
if git_branch && git_branch == 'production' | |
knife_env = 'production' | |
else | |
knife_env = 'development' | |
end | |
end | |
# Defaults | |
knife_org ||= 'moriz' | |
knife_config_dir ||= '~/.chef' | |
knife_config_file ||= 'KNIFE_ORG-KNIFE_ENV-knife.rb' | |
knife_config_file.gsub!(/KNIFE_ENV/, knife_env ).gsub!(/KNIFE_ORG/, knife_org) | |
# the "real" knife file e.g.: | |
# ~/.chef/myorganization-development-knife.rb | |
# OR ~/.chef/myorganization-production-knife.rb | |
# | |
knife_file = File.expand_path knife_config_dir + '/' + knife_config_file | |
unless File.exists? knife_file | |
puts "*" * 80 | |
puts "!!! Could not read #{knife_file} !!!" | |
puts | |
puts " => please create this file OR provide settings through the environment." | |
puts "*" * 80 | |
puts " (see: #{__FILE__} for the loading logic)" | |
exit 1 | |
else | |
puts knife_file | |
# check this url for more details: | |
# https://github.com/opscode/mixlib-config/blob/master/lib/mixlib/config.rb#L36 | |
Chef::Config.from_file knife_file | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment