Skip to content

Instantly share code, notes, and snippets.

@giuliocalzolari
Created July 20, 2015 15:12
Show Gist options
  • Save giuliocalzolari/8505b0bc9c99e2008b81 to your computer and use it in GitHub Desktop.
Save giuliocalzolari/8505b0bc9c99e2008b81 to your computer and use it in GitHub Desktop.
Multiple Knife configuration
# adaptive knife.rb
def colorize(text, color_code)
"\e[#{color_code}m#{text}\e[0m"
end
def red(text); colorize(text, 31); end
def green(text); colorize(text, 32); end
DEF_OPSORGNAME = "demo-org"
if ENV['OPSORGNAME'].nil?
OPSORGNAME = "#{DEF_OPSORGNAME}"
puts red("OPSORGNAME is not defined")
puts red(" export OPSORGNAME=#{OPSORGNAME}")
elsif ENV['OPSORGNAME'] == ""
OPSORGNAME = "#{DEF_OPSORGNAME}"
puts red("OPSORGNAME is empty")
puts red(" export OPSORGNAME=#{OPSORGNAME}")
else
OPSORGNAME = ENV['OPSORGNAME']
puts green("OPSORGNAME is defined: #{OPSORGNAME}")
puts green(" export OPSORGNAME=#{OPSORGNAME}")
end
log_level :info
log_location STDOUT
node_name 'giuliocalzo'
client_key "~/.chef/user-#{OPSORGNAME}.pem"
validation_client_name "chef-validator"
validation_key "~/.chef/validator-#{OPSORGNAME}.pem"
if File.file?("knife-#{OPSORGNAME}.rb")
chef_server_url = ""
eval File.open("knife-#{OPSORGNAME}.rb").read
else
puts red("ERROR no file found knife-#{OPSORGNAME}.rb ")
chef_server_url "https://api.opscode.com/organizations/#{OPSORGNAME}.rb"
end
syntax_check_cache_path '~/.chef/syntax_check_cache'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment