Multiple roles with attributes (?) In Capistrano
How do I pass attributes to my tasks in capistrano?
My goal is to deploy to multiple servers in a load balancer. I would like to pull each one out, deploy and add it back in sequence so that there is no server left at any time.
I think it will be something like strings ... (and the hosts array will be generated dynamically upon request from 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?
a source to share
Nobody knows? I found something about the sequential block below, but this is as far as I got it ...
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 using cap.
a source to share
Justin, I wish this is not possible, once the thread pool is open (first run
on the server) there is no way to access the server properties. (since the code run
doesn't run for every server, not for pooling mappings). Some people have had some success with this, but this is actually a sign that your scripts need too much information that you must extract from your production environment.
As with this, it seems that you are doing something like using the hostname to navigate to the script, use what Unix gives you:
run "./my_script.rb `hostname`"
Will that work?
Literature:
• 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)
a source to share