Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is a "role" in Capistrano?

What is the purpose and function of "roles" in a Capistrano recipe? When I look at sample recipes, I often see something like this:

role :app, 'somedomain.com' role :web, 'somedomain.com' role :db,  'somedomain.com', :primary => true 

So it looks like a role is basically a server where Capistrano executes commands. If that's the case, then why would it be called a "role" rather than a "host" or "server"?

In the above example, what is the difference between the :app and :web roles?

What does the :primary => true option do?

like image 893
Ethan Avatar asked Jul 20 '09 18:07

Ethan


People also ask

What is role in Capistrano?

You can use the role filter to restrict Capistrano tasks to only servers match a given role or roles. If the filter matches no servers, no actions will be taken. If you specify a filter, it will match any servers that have that role, and it will run all tasks for each of the roles that server has.

What is Capistrano gem?

Capistrano is a framework for building automated deployment scripts. Although Capistrano itself is written in Ruby, it can easily be used to deploy projects of any language or framework, be it Rails, Java, or PHP.


1 Answers

Roles allow you to write capistrano tasks that only apply to certain servers. This really only applies to multi-server deployments. The default roles of "app", "web", and "db" are also used internally, so their presence is not optional (AFAIK)

In the sample you provided, there is no functional difference.

The ":primary => true" is an attribute that allows for further granularity in specifying servers in custom tasks.

Here is an example of role specification in a task definition:

task :migrate, :roles => :db, :only => { :primary => true } do   # ... end 

See the capistrano website @ https://github.com/capistrano/capistrano/wiki/2.x-DSL-Configuration-Roles-Role for a more extensive explanation.

like image 175
codeprimate Avatar answered Sep 26 '22 02:09

codeprimate