shadow_coder shadow_coder - 3 months ago 9
Ruby Question

Executing commands based on the role inside a task in capistrano

I have a pseudo as follows

task :my_task, roles => [:role1, :role2] do
command 1
command 2
command 3
command 4
end


I want to run command 1 & command 2, only for role1, command 3 & command 4,for role2. Is this possible in capistrano?

I tried,

task :my_task, roles => [:role1, :role2] do
on roles(:role1) do
command 1
command 2
end

on roles(:role2) do
command 3
command 4
end
end


But didn't seem to work for me..Please help :)

Btwn, I'm using Capistrano v2.15.5

Thanks in advance

Answer

This may not be a great way of solving it..but this was all I could and it worked for me.

task :my_task do
    task_1
    task_2
end
task :task_1, :roles => [:role1] do
    command 1
    command 2
end
task :task_2, :roles => [:role2] do
    command 3
    command 4
end