Glad it worked for you

Donovan Bray
Registered Capistrano Abuser

On Jan 23, 2013, at 12:29 PM, Christopher Opena <[email protected]> wrote:

> Many thanks for the response, Donovan.  In truth we're abusing a lot of 
> Capistrano's default workings due to our current setup (almost a thousand 
> instances of a single app, each of which could be on any given server as 
> :primary and any given server as :secondary, depending on current 
> conditions).  Basically we've defined our instances in one yaml and servers 
> in another yaml, and these yaml files are constantly shifting and being 
> updated due to environmental factors so our tasks have to be pretty flexible 
> in how to define the members of a given role.
> 
> We do load in all of the roles before any of the tasks are defined, so that 
> should at least help here.
> 
> In any case, I have modified the task to your suggestion and it works 
> perfectly - thanks!
> 
> On Tue, Jan 22, 2013 at 6:28 PM, Donovan Bray <[email protected]> wrote:
> I think you are abusing primary and the :only clause
> 
> I would create specific roles and target tasks to those roles. 
> 
> Ie 
> 
> server 'server20', :app, :app_primary
> server 'server21', :app, :app_secondary
> server 'server22'. :app
> 
> Now you can cut your servers all 3 ways by role. 
> 
> If you insist on doing an 'OR' it will need to look something like this:
> 
> task :test, :hosts => find_servers(:roles => :app, :only =>{:primary => 
> true}) + find_servers(:roles => :app, :only =>{:secondary => true}) do ...
> 
> That makes the huge assumption you assign all of the servers and roles before 
> that task is defined in ruby; otherwise you'll always end up with an empty 
> list. 
> 
> If that's the case you have to do it on the run command that way the 
> find_servers method is evaluated at runtime as opposed to load time. 
> 
> task :test do
>   run "uptime", :hosts => find_servers(:roles => :app, :only =>{:primary => 
> true}) + find_servers(:roles => :app, :only =>{:secondary => true})
> end
> 
> 
> On Jan 21, 2013, at 11:50 AM, Christopher Opena <[email protected]> wrote:
> 
>> Is it possible to pass an OR conditional into the :only check?  I know that 
>> it expects an array of key/value pairs so you can essentially do an AND 
>> inside of the hash, but what if you want to check on multiple keys in the 
>> conditional?
>> 
>> Example:
>> 
>> I have ten servers in a bank that are all serving the application.  At any 
>> point in time, only the :primary and the :secondary should have actions 
>> performed on them.  Through capistrano definitions I have managed to pass 
>> :primary => true and :secondary => true into those two servers, such that 
>> (stripped all the other servers out of the array to save space):
>> 
>> [
>> #<Capistrano::ServerDefinition:0x101968618
>>     @hash=-2051751815,
>>     @host="server21.domain.com",
>>     @options={:secondary=>true},
>>     @port=nil,
>>     @to_s="[email protected]",
>>     @user="user">,
>> #<Capistrano::ServerDefinition:0x10194ad98
>>     @hash=6964762022,
>>     @host="server20.domain.com",
>>     @options={:primary=>true},
>>     @port=nil,
>>     @to_s="[email protected]",
>>     @user="user">,
>> #<Capistrano::ServerDefinition:0x10194cb20
>>     @hash=-447395779,
>>     @host="server22.domain.com",
>>     @options={},
>>     @port=nil,
>>     @to_s="[email protected]",
>>     @user="user">,
>> ]
>> 
>> If I want to run a task *only* on those two (the list is much longer, just 
>> stripped for this example), is there some iteration of :only that allows me 
>> to do that?  I have attempted:
>> 
>> task :test, :roles => [:app], :only => {:primary => true} || {:secondary => 
>> true} do; run "hostname"; end
>> 
>> But it only executes on the first matching hash of k,v pair.  And of course, 
>> if you do:
>> 
>> task :test, :roles => [:app], :only => {:primary => true, :secondary => 
>> true} do; run "hostname"; end
>> 
>> It will attempt to match both k,v pairs.  Anyone have any suggestions?  It's 
>> probably just something syntactical that I'm totally overlooking.
>> 
>> Thanks in advance,
>> Chris.
>> -- 
>> * You received this message because you are subscribed to the Google Groups 
>> "Capistrano" group.
>> * To post to this group, send email to [email protected]
>> * To unsubscribe from this group, send email to 
>> [email protected] For more options, visit this group 
>> at http://groups.google.com/group/capistrano?hl=en
> 
> -- 
> * You received this message because you are subscribed to the Google Groups 
> "Capistrano" group.
> * To post to this group, send email to [email protected]
> * To unsubscribe from this group, send email to 
> [email protected] For more options, visit this group at 
> http://groups.google.com/group/capistrano?hl=en
> 
> -- 
> * You received this message because you are subscribed to the Google Groups 
> "Capistrano" group.
> * To post to this group, send email to [email protected]
> * To unsubscribe from this group, send email to 
> [email protected] For more options, visit this group at 
> http://groups.google.com/group/capistrano?hl=en

-- 
* You received this message because you are subscribed to the Google Groups 
"Capistrano" group.
* To post to this group, send email to [email protected]
* To unsubscribe from this group, send email to 
[email protected] For more options, visit this group at 
http://groups.google.com/group/capistrano?hl=en

Reply via email to