Module: Capistrano::Configuration::Servers
- Included in:
- Capistrano::Configuration
- Defined in:
- lib/capistrano/configuration/servers.rb
Instance Method Summary collapse
-
#find_servers(options = {}) ⇒ Object
Attempts to find all defined servers that match the given criteria.
-
#find_servers_for_task(task, options = {}) ⇒ Object
Identifies all servers that the given task should be executed on.
Instance Method Details
#find_servers(options = {}) ⇒ Object
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 => "[email protected]"
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/capistrano/configuration/servers.rb', line 44 def find_servers(={}) return [] if .key?(:hosts) && ([:hosts].nil? || [] == [:hosts]) return [] if .key?(:roles) && ([:roles].nil? || [] == [:roles]) hosts = server_list_from(ENV['HOSTS'] || [:hosts]) if hosts.any? if [:skip_hostfilter] hosts.uniq else filter_server_list(hosts.uniq) end else roles = role_list_from(ENV['ROLES'] || [:roles] || self.roles.keys) roles = roles & Array([:roles]) if preserve_roles && ![:roles].nil? only = [:only] || {} except = [: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.[key] == value } } servers = servers.reject { |server| except.any? { |key,value| server.[key] == value } } if [:skip_hostfilter] servers.uniq else filter_server_list(servers.uniq) end end end |
#find_servers_for_task(task, options = {}) ⇒ Object
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.
8 9 10 |
# File 'lib/capistrano/configuration/servers.rb', line 8 def find_servers_for_task(task, ={}) find_servers(task..merge()) end |