I'm trying to set up a capfile that will execute certain different
instructions for the same "task" on two different roles.  In other
words, during my "finalize_update" I need to set up some different
links depending on the tier of the application.  The only way I could
think to do this was to have the main "finalize_update" task call two
child tasks that each have the appropriate role restriction.  My
problem is that when I try to just update one tier (using the ROLES
environment variable) it executes both of the child tasks, even though
one of them is restricted to a role other than the one I specified.
It seems it only evaluates the ROLES variable to determine invocation
of the top level task, but then any tasks that it calls are executed
regardless of their role restriction.  What is particularly
interesting, I suppose, is that it doesn't run the child task on my
excluded role on the hosts for that role, but rather runs both tasks
on the hosts of the role that I did specify, even though they aren't
in that role.

Is there a better way to do conditional logic by role for a task that
is common to multiple roles?  Shouldn't the role restrictions be
enforced even for called tasks?

My capfile - somewhat modified  :)

role :alpha, "alpha01", "alpha02"
role :beta, "beta01", "beta02"

task :both do
  alpha_only
  beta_only
end

task :alpha_only, :roles => :alpha do
  run "echo 'only on alpha'"
end

task :beta_only, :roles => :beta do
  run "echo 'only on beta'"
end

Which results in:

-bash-3.00$ cap main ROLES=alpha
  * executing `both'
  * executing `alpha_only'
  * executing "echo 'only on alpha'"
    servers: ["alpha01", "alpha02"]
    [alpha01] executing command
    [alpha02] executing command
 ** [out :: alpha02] only on alpha
 ** [out :: alpha01] only on alpha
    command finished
  * executing `beta_only'
  * executing "echo 'only on beta'"
    servers: ["alpha01", "alpha02"]
    [alpha01] executing command
    [alpha02] executing command
 ** [out :: alpha02] only on beta
 ** [out :: alpha01] only on beta
    command finished


--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---

Reply via email to