Roles apparently cannot be set within a task dynamically at runtime --
this message told me so: "/usr/local/lib/ruby/gems/1.8/gems/
capistrano-2.0.0/lib/capistrano/configuration/namespaces.rb:170:in
`role': roles cannot be defined in a namespace (NotImplementedError)"
Has anyone encountered this problem? If so, what solution do you
suggest?
The code inside the block can do actually anything.
Then you can use your role in tasks this way:
task :check_app_status, :roles => myrole do
The important thing here is that you must place "set(:myrole)" statement
strictly before the definition of any task that uses "myrole".
2) The dirtier but more dynamic solution:
parent.roles[:myrole] = [] #clearing the role servers list
parent.role :myrole, server_host #appending the hostname to the role
Hope this would help.
--
Cheers,
Michael
The first solution dynamically sets a variable to a symbol -- the
symbol can be used to look up statically declared host-roles.
However, I have a dynamic host.
The second solution throws this error: /usr/local/lib/ruby/gems/1.8/
gems/capistrano-2.0.0/lib/capistrano/configuration/connections.rb:
121:in `execute_on_servers': undefined method `host' for
"ec2-67-202-12-42.z-1.compute-1.amazonaws.com":String (NoMethodError).
I could keep hacking, but I figured it'd be wiser to get a Community
Approved Solution (tm).
and then in one of your recipies you can have the following task definition:
task :check_app_status, :roles => dynamic_host do
..
end
In this case the task's role will be the 'dynamic_host' contents.
>
> The second solution throws this error: /usr/local/lib/ruby/gems/1.8/
> gems/capistrano-2.0.0/lib/capistrano/configuration/connections.rb:
> 121:in `execute_on_servers': undefined method `host' for
> "ec2-67-202-12-42.z-1.compute-1.amazonaws.com":String (NoMethodError).
Sorry, the right variant is the:
arent.roles[:myrole] = [] #clearing the role servers list
parent.role :myrole, Capistrano::ServerDefinition.new(server_host)
--
Cheers,
Michael
parent.roles[:myrole] =
[Capistrano::ServerDefinition.new(my_staging_name)]
This is definately not part of the api, but at this time its the only
way I've found to make it work. Any cleaner solutions welcome.