Unknown role ArgumentError

223 views
Skip to first unread message

Brian Takita

unread,
Feb 2, 2009, 6:09:15 PM2/2/09
to capis...@googlegroups.com
I'm on a project where I'm trying to use a capistrano script for
different stages.
One stage has a utility role and does not have a database, web, app,
or memcache server. The other stages do.

I want to reuse some of the cap tasks that I use for a normal deploy,
however, when I try to deploy to the utility stage, I receive:
/usr/local/lib/ruby/gems/1.8/gems/capistrano-2.5.3/lib/capistrano/configuration/servers.rb:75:in
`role_list_from': unknown role `db_admin' (ArgumentError)

I would like to ignore the task, since the utility role is not
specified for that task.
Has anybody else run into this issue? What is the idiom to get around this?

Thank you,
Brian Takita

Brian Takita

unread,
Feb 2, 2009, 6:12:08 PM2/2/09
to capis...@googlegroups.com
To fix this, I implemented the following monkey-patches. However, I
don't want to be incompatible with the Capistrano idioms if I can
avoid it.

http://gist.github.com/57165

Jamis Buck

unread,
Feb 2, 2009, 6:24:02 PM2/2/09
to capis...@googlegroups.com
Sadly, Capistrano doesn't currently let you declare a role without
servers, but you can work around it like this:

roles[:db_admin]

Just that, on a line of it's own, will tell Capistrano that there is a
role named :db_admin. It won't have any servers in it (unless you later
do role(:db_admin,...)).

From there, you'll then need to make sure your tasks know not to try and
run anything if there are no matching servers (otherwise, cap complains
that no servers matched). Something like this:

task :something, :roles => :db_admin do
next if find_servers_for_task(current_task).empty?
# ...
end

And that should do it. In light of the hacks this requires, I'd be
willing to consider two patches:

1. allow role() to take only a role name, without servers, so that you
can "declare" an empty role.

2. add an option to task() so that it is skipped if there are no
matching servers, or which causes run() to be silent in that case.

- Jamis
Reply all
Reply to author
Forward
0 new messages