Module: Capistrano::Configuration::Roles

### Home Classes Methods

### In Files

- lib/capistrano/configuration/roles.rb

### Methods

- #role
- #role_names_for_host
- #server

### Files

- help.txt

### Class/Module Index

Quicksearch

- Capistrano
- Capistrano::CLI
- Capistrano::CLI::Execute
- Capistrano::CLI::Execute::ClassMethods
- Capistrano::CLI::Help
- Capistrano::CLI::Options
- Capistrano::CLI::Options::ClassMethods
- Capistrano::CLI::UI
- Capistrano::CLI::UI::ClassMethods
- Capistrano::Callback
- Capistrano::Command
- Capistrano::Command::Tree
- Capistrano::Command::Tree::Branch
- Capistrano::Command::Tree::ConditionBranch
- Capistrano::Command::Tree::ConditionBranch::Evaluator
- Capistrano::Command::Tree::ElseBranch
- Capistrano::Configuration
- Capistrano::Configuration::Actions
- Capistrano::Configuration::Actions::FileTransfer
- Capistrano::Configuration::Actions::Inspect
- Capistrano::Configuration::Actions::Invocation
- Capistrano::Configuration::Actions::Invocation::ClassMethods
- Capistrano::Configuration::AliasTask
- Capistrano::Configuration::Callbacks
- Capistrano::Configuration::Connections
- Capistrano::Configuration::Execution
- Capistrano::Configuration::Loading
- Capistrano::Configuration::Loading::ClassMethods
- Capistrano::Configuration::LogFormatters
- Capistrano::Configuration::Namespaces
- Capistrano::Configuration::Namespaces::Namespace
- Capistrano::Configuration::Roles
- Capistrano::Configuration::Servers
- Capistrano::Configuration::Variables
- Capistrano::Deploy
- Capistrano::Deploy::Dependencies
- Capistrano::Deploy::LocalDependency
- Capistrano::Deploy::RemoteDependency
- Capistrano::Deploy::SCM
- Capistrano::Deploy::SCM::Accurev
- Capistrano::Deploy::SCM::Accurev::InternalRevision
- Capistrano::Deploy::SCM::Base
- Capistrano::Deploy::SCM::Base::LocalProxy
- Capistrano::Deploy::SCM::Bzr
- Capistrano::Deploy::SCM::Cvs
- Capistrano::Deploy::SCM::Darcs
- Capistrano::Deploy::SCM::Git
- Capistrano::Deploy::SCM::Mercurial
- Capistrano::Deploy::SCM::None
- Capistrano::Deploy::SCM::Perforce
- Capistrano::Deploy::SCM::Subversion
- Capistrano::Deploy::Strategy
- Capistrano::Deploy::Strategy::Base
- Capistrano::Deploy::Strategy::Checkout
- Capistrano::Deploy::Strategy::Copy
- Capistrano::Deploy::Strategy::Export
- Capistrano::Deploy::Strategy::Remote
- Capistrano::Deploy::Strategy::RemoteCache
- Capistrano::Deploy::Strategy::UnsharedRemoteCache
- Capistrano::ProcCallback
- Capistrano::Processable
- Capistrano::Processable::SessionAssociation
- Capistrano::RemoteError
- Capistrano::Role
- Capistrano::Role::DynamicServerList
- Capistrano::SSH
- Capistrano::ServerDefinition
- Capistrano::Shell
- Capistrano::TaskCallback
- Capistrano::TaskDefinition
- Capistrano::Transfer
- Capistrano::Transfer::SFTPTransferWrapper
- Capistrano::Version
- Kernel
- Object
- String

No matching classes.

# Capistrano::Configuration::Roles

### Attributes

roles[R]

The hash of roles defined for this configuration. Each entry in the hash points to an array of server definitions that belong in that role.

### Public Instance Methods

role(which, *args, &block) click to toggle source

Define a new role and its associated servers. You must specify at least one host for each role. Also, you can specify additional information (in the form of a Hash) which can be used to more uniquely specify the subset of servers specified by this specific role definition.

Usage:

    role :db,  "db1.example.com", "db2.example.com"
    role :db,  "master.example.com", :primary => true
    role :app, "app1.example.com", "app2.example.com"

You can also encode the username and port number for each host in the server string, if needed:

    role :web,  "www@web1.example.com"
    role :file, "files.example.com:4144"
    role :db,   "admin@db3.example.com:1234"

Lastly, username and port number may be passed as options, if that is preferred; note that the options apply to all servers defined in that call to "role":

    role :web, "web2", "web3", :user => "www", :port => 2345

    # File lib/capistrano/configuration/roles.rb, line 45
    def role(which, *args, &block)
      options = args.last.is_a?(Hash) ? args.pop : {}
      which = which.to_sym

      # The roles Hash is defined so that unrecognized keys always auto-initialize
      # to a new Role instance (see the assignment in the initialize_with_roles method,
      # above). However, we explicitly assign here so that role declarations will
      # vivify the role object even if there are no server arguments. (Otherwise,
      # role(:app) won't actually instantiate a Role object for :app.)
      roles[which] ||= Role.new

      roles[which].push(block, options) if block_given?
      args.each { |host| roles[which] << ServerDefinition.new(host, options) }
    end

role_names_for_host(host) click to toggle source

    # File lib/capistrano/configuration/roles.rb, line 72
    def role_names_for_host(host)
      roles.map {|role_name, role| role_name if role.include?(host) }.compact || []
    end

server(host, *roles) click to toggle source

An alternative way to associate servers with roles. If you have a server that participates in multiple roles, this can be a DRYer way to describe the relationships. Pass the host definition as the first parameter, and the roles as the remaining parameters:

    server "master.example.com", :web, :app

    # File lib/capistrano/configuration/roles.rb, line 66
    def server(host, *roles)
      options = roles.last.is_a?(Hash) ? roles.pop : {}
      raise ArgumentError, "you must associate a server with at least one role" if roles.empty?
      roles.each { |name| role(name, host, options) }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.