Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

List of servers #52

Closed
jamsi opened this Issue · 12 comments

3 participants

James Martin Ryan Conway Tim Goodwin
James Martin

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.

Ryan Conway
Owner

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
end

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.

James Martin

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?

Ryan Conway
Owner

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

James Martin

Yep, using multistage.

James Martin

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
Ryan Conway
Owner

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?

James Martin

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

Deploy.rb

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

and

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} 
Tim Goodwin

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
Ryan Conway
Owner

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

James Martin

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

Ryan Conway
Owner

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

Ryan Conway
Owner

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

Ryan Conway 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.