Module: Capistrano::Configuration::Groups

Included in:
Capistrano::Configuration
Defined in:
lib/capistrano/ec2group.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) group(which, *args)

Associate a group of EC2 instances with a role. In order to use this, you must use the security groups feature in Amazon EC2 to group your servers by role.

First, specify the security group name, then the roles and params:

group :webserver, :web
group :app_myappname, :app
group "MySQL Servers", :db, :port => 22000


19
20
21
22
23
24
25
26
27
# File 'lib/capistrano/ec2group.rb', line 19

def group(which, *args)
  @ec2_api ||= RightAws::Ec2.new(fetch(:aws_access_key_id), fetch(:aws_secret_access_key), fetch(:aws_params, {}))

  @ec2_api.describe_instances.delete_if{|i| i[:aws_state] != "running"}.each do |instance|
    instance[:groups].each do |group|
      server(fetch(:aws_pvt_dns) ? instance[:private_dns_name] : instance[:dns_name], *args) if group[:group_name] == which.to_s
    end
  end
end