Module: Capistrano::Configuration::Servers

### Home Classes Methods

### In Files

- lib/capistrano/configuration/servers.rb

### Methods

- #build_list
- #filter_server_list
- #find_servers
- #find_servers_for_task
- #role_list_from
- #server_list_from

### 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::Servers

### Public Instance Methods

find_servers(options={}) click to toggle source

Attempts to find all defined servers that match the given criteria. The options hash may include a :hosts option (which should specify an array of host names or ServerDefinition instances), a :roles option (specifying an array of roles), an :only option (specifying a hash of key/value pairs that any matching server must match), an :exception option (like :only, but the inverse), and a :skip_hostfilter option to ignore the HOSTFILTER environment variable described below.

Additionally, if the HOSTS environment variable is set, it will take precedence over any other options. Similarly, the ROLES environment variable will take precedence over other options. If both HOSTS and ROLES are given, HOSTS wins.

Yet additionally, if the HOSTFILTER environment variable is set, it will limit the result to hosts found in that (comma-separated) list.

If the HOSTROLEFILTER environment variable is set, it will limit the result to hosts found in that (comma-separated) list of roles

Usage:

    # return all known servers
    servers = find_servers

    # find all servers in the app role that are not exempted from
    # deployment
    servers = find_servers :roles => :app,
                 :except => { :no_release => true }

    # returns the given hosts, translated to ServerDefinition objects
    servers = find_servers :hosts => "jamis@example.host.com"

    # File lib/capistrano/configuration/servers.rb, line 44
    def find_servers(options={})
      return [] if options.key?(:hosts) && (options[:hosts].nil? || [] == options[:hosts])
      return [] if options.key?(:roles) && (options[:roles].nil? || [] == options[:roles])

      hosts  = server_list_from(ENV['HOSTS'] || options[:hosts])

      if hosts.any?
        if options[:skip_hostfilter]
          hosts.uniq
        else
          filter_server_list(hosts.uniq)
        end
      else
        roles = role_list_from(ENV['ROLES'] || options[:roles] || self.roles.keys)
        roles = roles & Array(options[:roles]) if preserve_roles && !options[:roles].nil?

        only   = options[:only] || {}
        except = options[:except] || {}

        # If we don't have a def for a role it means its bogus, skip it so higher level can handle
        servers = roles.inject([]) { |list, role| list.concat(self.roles[role] || []) }
        servers = servers.select { |server| only.all? { |key,value| server.options[key] == value } }
        servers = servers.reject { |server| except.any? { |key,value| server.options[key] == value } }

        if options[:skip_hostfilter]
          servers.uniq
        else
          filter_server_list(servers.uniq)
        end
      end
    end

find_servers_for_task(task, options={}) click to toggle source

Identifies all servers that the given task should be executed on. The options hash accepts the same arguments as find_servers, and any preexisting options there will take precedence over the options in the task.

    # File lib/capistrano/configuration/servers.rb, line 8
    def find_servers_for_task(task, options={})
      find_servers(task.options.merge(options))
    end

### Protected Instance Methods

build_list(list) click to toggle source

    # File lib/capistrano/configuration/servers.rb, line 111
    def build_list(list)
      Array(list).map { |item| item.respond_to?(:call) ? item.call : item }.flatten
    end

filter_server_list(servers) click to toggle source

    # File lib/capistrano/configuration/servers.rb, line 78
    def filter_server_list(servers)
      return servers unless ENV['HOSTFILTER'] or ENV['HOSTROLEFILTER']
      if ENV['HOSTFILTER']
        filters = ENV['HOSTFILTER'].split(/,/)
        servers.select { |server| filters.include?(server.host) }
      elsif ENV['HOSTROLEFILTER']
        filters = ENV['HOSTROLEFILTER'].split(/,/).map do |role|
          local_roles = roles[role.to_sym]
          if local_roles.is_a? Array
            roles[role.to_sym]
          else
            roles[role.to_sym].servers
          end
        end.flatten
        servers.select { |server| filters.include?(server) }
      end
    end

role_list_from(roles) click to toggle source

    # File lib/capistrano/configuration/servers.rb, line 102
    def role_list_from(roles)
      roles = roles.split(/,/) if String === roles
      roles = build_list(roles)
      roles.map do |role|
        role = String === role ? role.strip.to_sym : role
        role
      end
    end

server_list_from(hosts) click to toggle source

    # File lib/capistrano/configuration/servers.rb, line 96
    def server_list_from(hosts)
      hosts = hosts.split(/,/) if String === hosts
      hosts = build_list(hosts)
      hosts.map { |s| String === s ? ServerDefinition.new(s.strip) : s }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.