class Capistrano::Configuration

Public Instance Methods

for_each_ec2_server(ec2_env:, ec2_role:) { |ec2_server, index| ... } click to toggle source
# File lib/capistrano/ec2/capistrano_monkey_patch.rb, line 5
def for_each_ec2_server(ec2_env:, ec2_role:, &block)
  filters = {
    'tag:ec2_env' => ec2_env,
    'tag:role' => ec2_role,
    'instance-state-name': 'running'
  }

  ec2.servers.all(filters).map.with_index do |ec2_server, index|
    next unless ec2_server.ready?

    yield ec2_server, index
  end
end

Private Instance Methods

access_key_options() click to toggle source
# File lib/capistrano/ec2/capistrano_monkey_patch.rb, line 50
def access_key_options
  {
    aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
    aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
    aws_session_token: ENV['AWS_SESSION_TOKEN'],
  }
end
ec2() click to toggle source
# File lib/capistrano/ec2/capistrano_monkey_patch.rb, line 21
def ec2
  @ec2 ||= Fog::Compute.new(fog_arguments)
end
fog_arguments() click to toggle source
# File lib/capistrano/ec2/capistrano_monkey_patch.rb, line 25
def fog_arguments
  default_options = {
    provider: 'AWS',
    region: region,
  }

  if use_iam_profile
    default_options.merge(iam_profile_options)
  else
    default_options.merge(access_key_options)
  end
end
iam_profile_options() click to toggle source
# File lib/capistrano/ec2/capistrano_monkey_patch.rb, line 46
def iam_profile_options
  { use_iam_profile: true }
end
region() click to toggle source
# File lib/capistrano/ec2/capistrano_monkey_patch.rb, line 38
def region
  fetch(:region)
end
use_iam_profile() click to toggle source
# File lib/capistrano/ec2/capistrano_monkey_patch.rb, line 42
def use_iam_profile
  fetch(:use_iam_profile, false)
end