Skip to content


Subversion checkout URL

You can clone with
Download ZIP


List of servers #52

jamsi opened this Issue · 12 comments

3 participants


Is it possible to get a list of servers in a particular Role in some sort of variable?
As an example, I need to rsync something to all servers with the Role: web in a custom task. Currently I have 4 rsync run commands, one for each server - but obviously this isn't dynamic.


You can get a hash with all available role data in the 'roles' variable. You might try poking about with that to see if it will do what you need?

Put this task in your deploy.rb and run it to see:

task :roles_test do
  puts roles.inspect

Each role should be available as a symbol in that hash, containing a Capistrano::Role object, which has a @static_servers instance variable containing all EC2 instances in that role.

We could probably add some helpers to Capify-EC2 to make these sorts of tasks easier.


OK cheers, that sounds good. However I have;

require 'capify-ec2/capistrano'
ec2_roles name: :web 

Yet for the life of me, your task doesn't output any servers in the roles object.
The status command;

cap production ec2:status

Works fine though. Any ideas?


How strange! Are you using Capistrano multistage or anything like that?


Yep, using multistage.


Just wondering if we could revisit this. So cap production ec2:server_names and cap production ec2:status seem to output my desired servers.

Yet running

cap production deploy 

Results in;

`deploy:update_code' is only run for servers matching {:except=>{:no_release=>true}}, but no servers matched

Hey there @jamsi, yeah I'm not sure we support Multistage fully (or at all), so I'm wondering if that is part of the problem. Would it be possible to attach a Gist of your configuration, without anything sensitive of course, and I'll try to reproduce it locally so I can debug it?


I must be doing something terribly wrong, as I've attempted this on a project without multi stage.


require "capify-ec2/capistrano"
ec2_roles {:name => :web}


cap deploy
/Users/james/.rvm/gems/ruby-2.0.0-p353/gems/capistrano-    2.15.5/lib/capistrano/configuration/loading.rb:93:in `instance_eval': ./config/deploy.rb:7: syntax error, unexpected =>, expecting '}' (SyntaxError) ec2_roles {:name => :web} 

the issue looks to be bad ruby syntax. try:

require "capify-ec2/capistrano"
ec2_roles({:name => :web})

without the parentheses, its interpreting the { ... } as a block

your other option is drop the {} altogether

require "capify-ec2/capistrano"
ec2_roles :name => :web

Thanks @trgoodwin, yes @jamsi in this case the syntax is incorrect. Does it work as expected now?


All good now. Appreciate it guys. Why on earth do the docs have examples with blocks? {} ?


Hmm they shouldn't do! That's a bug with the README! Apologies for that, I'll fix it.


Ok I've fixed the docs, I'm going to close this issue, feel free to re-open if there are any other problems :)

@Rylon Rylon closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.