views:

145

answers:

2

How can I pass along attributes to my tasks in capistrano?

My goal is to deploy to multiple servers in a load balancer. I'd like to take each one out, deploy, and add it back in sequentially so no more than one server is down at any time.

I'm thinking it would be something along the lines of... (and the hosts array would be generated dynamically after querying my load balancer)...

role :app, 
       [["server_one", {:instanceId => "alice"}], 
        ["server_two", {:instanceId => "bob"}],
        ["server_three", {:instanceId => "charles"}]]

And then for my tasks...

before :deploy, :deregister_instance_from_lb
after :deploy, :register_instance_with_lb

task deregister_instance_from_lb
  #TODO - Deregister #{instanceId} from load balancer
end

task register_instance_with_lb
  #TODO - Register #{instanceId} with load balancer
end

Any ideas?

+2  A: 

Justin, I'm sorry that's not possible, once the stream pool is opened (first run on a server set) there's no way to access server properties. (as the run code isn't run per-server, but against all-matching in the pool). Some people have had some success with doing something like this, but really it's a symptom that your scripts need too much information that you should be able to extract from your production environment.

As in this case it seems you are doing something like using the host's name to pass to a script, use what Unix gives you:

run "./my_script.rb `hostname`"

WIll that work?

References:

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html (Section 3.4.5)

http://unixhelp.ed.ac.uk/CGI/man-cgi?hostname (or $ man (1) hostname)

Beaks
Hi Lee, that is useful to know, but maybe not applicable to my situation - I think I oversimplified. Can you look at the revised question and let me know what you think?
Justin
A: 

No one knows? I found something about the sequential block below, but thats as far as I got...

find_servers.each do |server|
  #TODO - remove from load balancer
  #TODO - deploy
  #TODO - add back to load balancer
end

I find it hard to believe that no one has ever needed to do sequential tasks with cap.

Justin