Posted 8 months ago. Visible to the public.

Capistrano 2: How to deploy a single server

When you have a multi-server setup, you'll be adding a new server from time to time. Before doing a full deploy, you might want to test that server in an isolated deploy. There is a single way to do this: the HOSTFILTER env variable.

Commenting out "server" lines in the Capistrano deploy config will raise a Capistrano::NoMatchingServersError with <task> is only run for servers matching {:roles=> <role>}, but no servers matched. Instead, specify the server-under-test like this:

Copy cap production deploy

Capistrano is aware of this env variable and will only deploy that single server, skipping any tasks that do not apply. Profit!

As a side note, there is a secret Capistrano task option that will also silence the above exception. Generally it is a good idea that Capistrano complains when it doesn't have a server to run a (presumably important) task on. If you want it optional, define it like this:

task :my_task, on_no_matching_server: :continue do # Do stuff end

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Author of this card:

Dominik Schöler
Last edit:
8 months ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev