- From: Adam Jacob <adam@opscode.com>
- To: chef@lists.opscode.com
- Subject: Re: chef + vlad/capistrano?
- Date: Mon, 9 Mar 2009 10:27:12 -0700
On Mon, Mar 9, 2009 at 5:53 AM, Michal Frackowiak <michalf@wikidot.com> wrote:
>
1. New instances (nodes) register to chef-server first and get their
>
configuration from there, depending on their type (app, web, worker, db
>
etc). Role is passed as an attribute. We can launch new instances by
>
Capistrano tasks.
>
2. Capistrano pulls list of :app, :web, :db servers dynamically from
>
chef-server (or another registration server, iClassify?) through the role
>
defer option.
Something like this should work (this is totally untested)
require 'chef'
require 'chef/node'
require 'chef/rest'
# A registration for your API access
api_user = "monkey"
# A password for the API access
api_pass = "pants"
# A validation token, if you use them
validation_token = nil
# The chef server URL
chef_server_url = "
http://chefserver.example.com"
# The chef sever openid URL
chef_server_openid = "
http://chefserver.example.com:4001"
##
# This should move up into Chef::REST, see CHEF-168
# When it does, you'll do rest.search(...)
##
def search(type, query, attributes=[], &block)
Chef::Log.debug("Searching #{type} index with #{query}")
r = Chef::REST.new(chef_server_url)
results = r.get_rest("search/#{type}?q=#{query}&a=#{attributes.join(',')}")
Chef::Log.debug("Searching #{type} index with #{query} returned
#{results.length} entries")
if block
results.each do |sr|
block.call(sr)
end
else
results
end
end
rest = Chef::REST.new('
http://chefserver.example.com')
rest.register(api_user, api_pass, validation_token)
rest.authenticate(api_user, api_pass)
search(:node, 'environment:production') do |node|
role node[:role].to_sym, node[:fqdn]
end
This assumes each system has one role - if you want to get crazier, go
ahead and check to see if role is an array.
>
3. We can run cap tasks on the cluster.
Yep.
>
Obviously we want to add :app, :web or :worker on-the-fly, possibly with one
>
or two commands, and later move to auto-scaling solutions.
This is how we've done things in the past.
>
I am not sure if this is an optimal design, and I am sure you already have
>
an idea how Chef and Capistrano would eventually work. Any advice, ideo or a
>
hint would be highly appreciated.
I think you are on the right track - let us know how it works! I
would love to see this sort of thing broken in to a new project on
Github, at least as a loadable Chef library. If we can provide any
more assistance with using the Chef REST API to make this work, let us
know.
Adam
--
Opscode, Inc.
Adam Jacob, CTO
T: (206) 508-4759 E: adam@opscode.com
Archive powered by MHonArc 2.6.16.