Skip to content

Instantly share code, notes, and snippets.

@osamu
Created March 24, 2015 09:30
Show Gist options
  • Save osamu/ef7da34e01615322fb8b to your computer and use it in GitHub Desktop.
Save osamu/ef7da34e01615322fb8b to your computer and use it in GitHub Desktop.
require 'capistrano'
require 'aws-sdk'
module Capistrano
module Ec2tag
def self.extend(configuration)
configuration.load do
Capistrano::Configuration.instance.load do
_cset(:access_key_id, ENV['AWS_ACCESS_KEY_ID'])
_cset(:secret_access_key, ENV['AWS_SECRET_ACCESS_KEY'])
def tag(which, *args)
@ec2 ||= AWS::EC2.new({access_key_id: fetch(:aws_access_key_id), secret_access_key: fetch(:aws_secret_access_key)}.merge! fetch(:aws_params, {}))
AWS.memoize do
@ec2.instances.filter('tag-key', 'deploy').filter('tag-value', which).each do |instance|
server instance.private_ip_address, *args if instance.status == :running
end
end
end
end
end
end
end
end
if Capistrano::Configuration.instance
Capistrano::Ec2tag.extend(Capistrano::Configuration.instance)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment