Deploying to multiple hosts using Webistrano We're using Webistrano to deploy our Drupal sites to testing and production.

The recipe we're using is as follows:

namespace :drupal do
  desc "symlink_files"
  task :symlink_files do
    invoke_command "ln -s #{deploy_to}/shared/files #{deploy_to}/current/drupal/sites/default/"
    invoke_command "ln -s #{deploy_to}/shared/settings.php #{deploy_to}/current/drupal/sites/default/"
  end

  desc "refresh_configuration"
  task :refresh_configuration do
    invoke_command "cd #{deploy_to}/current/drupal; drush #{drush_options} -y fr-all"
    invoke_command "cd #{deploy_to}/current/drupal; drush #{drush_options} -y updb"
    invoke_command "cd #{deploy_to}/current/drupal; drush #{drush_options} cc all"
  end
end

after 'deploy:symlink','drupal:symlink_files','drupal:refresh_configuration'


This method is working great for single-host deployments, but fails for multi-host deployments. The reason is that the refresh_configuration task will run on each host, causing all kinds of race conditions and corruption on the central database server.

My question is, can anyone suggest a way to fix the Webistrano setup to only run refresh_configuration task on one server only? 

PS. I'm not interested in changing the deployment system to Aegir or anything else.
As per this Capistrano Wiki page, you can restrict tasks and single commands to specific :roles and :only attributes:

task :migrate, :roles =&gt; :db, :only =&gt; { :master =&gt; true } do
  # ...
end

task :other do
  run "migrate", :roles =&gt; :db, :only =&gt; { :master =&gt; true }
end


Using this, I was able to run the refresh_configuration task to run on a server with a specific attribute.