List of servers #52

Closed
jamsi opened this Issue Jan 6, 2014 · 12 comments

Projects

None yet

3 participants

@jamsi
jamsi commented Jan 6, 2014

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.

@Rylon
Member
Rylon commented Jan 9, 2014

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.

@jamsi
jamsi commented Jan 12, 2014

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?

@Rylon
Member
Rylon commented Jan 15, 2014

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

@jamsi
jamsi commented Jan 15, 2014

Yep, using multistage.

@jamsi
jamsi commented Mar 4, 2014

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
@Rylon
Member
Rylon commented Mar 12, 2014

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?

@jamsi
jamsi commented Mar 18, 2014

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} 
@trgoodwin

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
@Rylon
Member
Rylon commented Mar 18, 2014

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

@jamsi
jamsi commented Mar 18, 2014

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

@Rylon
Member
Rylon commented Mar 19, 2014

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

@Rylon
Member
Rylon commented Mar 19, 2014

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 Mar 19, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment