Top Level Namespace

Defined Under Namespace

Modules: Deploy

Instance Method Summary collapse

Instance Method Details

#_cdefault_run_options(key, value) ⇒ Object



7
8
9
10
11
# File 'lib/common.rb', line 7

def _cdefault_run_options(key, value)
  unless default_run_options.has_key? key
    default_run_options[key] = value
  end
end

#_cset(name, *args, &block) ⇒ Object



1
2
3
4
5
# File 'lib/common.rb', line 1

def _cset(name, *args, &block)
  unless exists?(name)
    set(name, *args, &block)
  end
end

#_cssh_options(key, value) ⇒ Object



13
14
15
16
17
# File 'lib/common.rb', line 13

def _cssh_options(key, value)
  unless ssh_options.has_key? key
    ssh_options[key] = value
  end
end

#aws_ec2_role(which, *args, &block) ⇒ Object

AWS.config(:logger => Rails.logger)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/deploy-recipes/aws-ec2.rb', line 6

def aws_ec2_role(which, *args, &block)
  
  options = args.last.is_a?(Hash) ? args.pop : {}
  
  # validate EC2 settings
  _cset(:access_key_id) { Capistrano::CLI.ui.ask("Enter your AWS access key ID: ") }
  _cset(:secret_access_key) { Capistrano::CLI.ui.ask("Enter your AWS secret key: ") }
  
  AWS.config :access_key_id => access_key_id, :secret_access_key => secret_access_key 
  
  ec2 = AWS::EC2.new
  # optionally switch to a non-default region
  if region = options[:region]
    region = ec2.regions[region]
    unless region.exists?
      raise "Requested region '#{region.name}' does not exist.  Valid regions: \n #{ec2.regions.map(&:name).join("\n  ")}"
    end
    # a region acts like the main EC2 interface
    ec2 = region
  end
  
  query = {}
  
  instances = AWS.memoize do
    query = {}
    # Filter by tags
    if tags = options[:tags]      
      args.delete :tags
      ec2.instances.select do |i|
        r = false
        tags.each do |key, value|
          if value
            r = i.tags.to_h[key.to_s] == value
          else
           r = i.tags.to_h.has_key? key.to_s
         end
        end
        r
      end
    end
  end
  # @TODO we need to make sure we merge the dns names with the other args
  args = instances.map {|i| i.dns_name}
  role which, *args
end