Top Level Namespace

Defined Under Namespace

Modules: Elbas

Instance Method Summary collapse

Instance Method Details

#autoscale(groupname, *args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/elbas/capistrano.rb', line 5

def autoscale(groupname, *args)
  include Capistrano::DSL
  include Elbas::Logger

  set :aws_autoscale_group_name, groupname

  asg = Elbas::AWS::AutoscaleGroup.new groupname
  instances = asg.instances.running

  instances.each do |instance|
    info "Adding server: #{instance.hostname}"
    server instance.hostname, *args
  end

  if instances.any?
    after 'deploy', 'elbas:deploy'
  else
    error <<~MESSAGE
      Could not create AMI because no running instances were found in the specified
      AutoScale group. Ensure that the AutoScale group name is correct and that
      there is at least one running instance attached to it.
    MESSAGE
  end
end