Restricting post-deployment tasks to certain roles using capistrano

Written by Ben Wendt

If you need to only run some tasks on a certain subset of servers in your inventory, first add a role to your inventory file deploy/whatever-environment.rb:

server '', roles: %w{my_role}

Now you can set up your command to run in one of your tasks in deploy.rb:

on roles(:my_role) do
  within release_path do
    with rails_env: fetch(:rails_env) do
      execute :bundle, :exec, :'script/', args, :all