views:

236

answers:

1

I have a task in capistrano wherein I want just a single line to run only if the server is a marked as primary. Is there a variable or method that I can reference inside a task? 'primary?' or 'primary' doesn't seem to work.

I've also tried something akin to the following:

after "deploy", "task1"
after "deploy", "task2"
after "deploy", "task3"

task :task1, :roles => :app do
  *code*
end

task :task2, :roles => :app, :only => {:primary => true} do
  *code for just primary server*
end

task :task3, :roles => :app do
  *more code*
end

But even this doesn't seem to work (all three tasks get run on every server).

I've been working on this on and off for a few days and I'm having no luck with my searches. Thoughts?

+1  A: 

I've solved the issue, but it wasn't pretty. The thing that I've found is that you need to use the 'primary => true' on a per-task basis. Looking at the code, it appears that capistrano generates a list of the servers that the task will be run on before the task is run.

Brian