Class: CapistranoAwsAutodiscover

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano-aws-autodiscover.rb,
lib/capistrano-aws-autodiscover/version.rb

Defined Under Namespace

Classes: Instance

Constant Summary collapse

VERSION =
"3.0.0"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, aws_region, project, environment) ⇒ CapistranoAwsAutodiscover

Returns a new instance of CapistranoAwsAutodiscover.



15
16
17
18
19
20
21
# File 'lib/capistrano-aws-autodiscover.rb', line 15

def initialize(key, secret, aws_region, project, environment)
  @key = key
  @secret = secret
  @region = aws_region
  @project = project.to_s
  @environment = environment.to_s
end

Class Method Details

.define_serversObject



8
9
10
11
12
13
# File 'lib/capistrano-aws-autodiscover.rb', line 8

def self.define_servers
  instances = CapistranoAwsAutodiscover.new(fetch(:aws_key_id), fetch(:secret_access_key), fetch(:aws_region), fetch(:ec2_project), fetch(:ec2_env)).execute
  instances.each do |s| 
    server s.dns, roles: s.roles, user: fetch(:user)
  end
end

Instance Method Details

#executeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/capistrano-aws-autodiscover.rb', line 23

def execute
  instances = ec2.describe_instances(instance_ids: tagged_instances,
                                     filters: [
                                       {name: "instance-state-name", values: ["running"]},
                                       {name: "tag:Env", values: [@environment]},
                                       {name: "tag:Project", values: [@project]},
                                       {name: "tag-key", values: ["Roles"]}
                                      ]
                                    )
  instances = instances.reservations.map {|r| r.instances }.flatten

  server_definitions(instances)
end