[chef] Re: How to target different servers/client-keys using knife?


Chronological Thread 
  • From: Alex Soto < >
  • To:
  • Subject: [chef] Re: How to target different servers/client-keys using knife?
  • Date: Tue, 19 Oct 2010 16:52:14 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:mime-version:content-type:subject:date:in-reply-to:to :references:message-id:x-mailer; b=J/Nu3+/uSak/Eo5yHklMy1fpaAUAt2K3h+btBvqu4au9t5QHLP2/RIOCFCNt0FVpfM cLXr25lnSmzuScqcm4bnNaRjMlxQzTF1drbwXszKD4W6jhx8gsbit6RhmTtscdYdjuVO XDJIxcCs+cap1zfvBymaw/lDz/AhR6cV3rfVU=

Sure, the idea is a knife.rb that evaluates a corresponding knife-config.BRANCHNAME.rb to override the config based on the git branch you are on.  Great example of the design win of having ruby as the config language.  You could DRY this up a bit, but this is version 1.  Looking forward to any 'patches'.

Alex

.chef/knife.rb

# Default to 'QA' environment
validation_client_name   'channels-qa-validator'
validation_key           './.chef/channels-qa-validator.pem'
chef_server_url          'https://api.opscode.com/organizations/channels-qa'  
cache_options( :path => './.chef/channels-qa-checksums' )

log_level                :debug
log_location             STDOUT
node_name                'apsoto'
client_key               '/Users/asoto/.chef/apsoto.pem'
cache_type               'BasicFile'
cookbook_path           './cookbooks','./site-cookbooks'

# Read in any environment specific config
branch_cmd = %q{git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'}
branch = `#{branch_cmd}`.strip
environment_config = File.join(File.dirname(__FILE__), "knife-config.#{branch}.rb")

if File.exists?(environment_config)
  eval(IO.read(environment_config))
  Chef::Log.info("Loaded environment specific configuration from #{environment_config}")
else
  Chef::Log.info("No environment specific config file found for branch #{branch}")
end


.chef/knife-config.master.rb
log_level                :info
log_location             STDOUT
validation_client_name   'channels-qa-validator'
validation_key           './.chef/channels-qa-validator.pem'
chef_server_url          'https://api.opscode.com/organizations/channels-qa'  
cache_options( :path => './.chef/channels-qa-checksums' )

.chef/knife-config.staging.rb
log_level                :debug
log_location             STDOUT
validation_client_name   'channels-staging-validator'
validation_key           './.chef/channels-staging-validator.pem'
chef_server_url          'https://api.opscode.com/organizations/channels-staging'  
cache_options( :path => './.chef/channels-staging-checksums' )


On Oct 19, 2010, at 3:34 PM, Mike Williams wrote:

On 20/10/2010, at 06:20 , Alex Soto wrote:

...

I also have my knife config determine what branch I'm on and configure the knife client to communicate with the corresponding server, setup correct keys, etc.

That sounds interesting.  How do you do that?  Have you got any code you can share?

--
cheers,
Mike Williams





Archive powered by MHonArc 2.6.16.

§