```ruby
require 'aws-sdk'

unless Capistrano::Configuration.respond_to?(:instance)
  abort 'capistrano/ec2tag requires Capistrano >= 2'
end

module Capistrano
  class Configuration
    module Tags

      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, {}))

        @ec2.instances.filter('tag-key', 'deploy').filter('tag-value', which).each do |instance|
          server instance.ip_address || instance.private_ip_address, *args if instance.status == :running
        end
      end

    end

    include Tags
  end
end
```

Load aws credentials from environment variables by default
user
```ruby
require 'aws-sdk'

unless Capistrano::Configuration.respond_to?(:instance)
  abort 'capistrano/ec2tag requires Capistrano >= 2'
end

module Capistrano
  class Configuration
    module Tags
      _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, {}))

        @ec2.instances.filter('tag-key', 'deploy').filter('tag-value', which).each do |instance|
          server instance.ip_address || instance.private_ip_address, *args if instance.status == :running
        end
      end

    end

    include Tags
  end
end
```
assistant