31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/dploy/deployer.rb', line 31
def deploy()
begin
search_tags = { 'project' => @deploy_data[:project], 'environment' => @deploy_data[:environment] }
@log.debug("Searching For EC2 Instances")
@log.debug("Search tags: #{search_tags}")
instances = @ec2.get_instances_by_tags(search_tags)
@log.debug("#{instances.count} matching instances found")
instances.each do |instance|
@log.debug("Starting deploy for instance: #{instance.id}")
node_name = "#{@deploy_data[:environment]}-#{@deploy_data[:project]}-#{instance.id}"
@log.debug("Updating chef node: #{node_name}")
attributes = { :dploy => { :target_version => @deploy_data[:version], :status => 'deploying' } }
@chef.update_node_attributes(node_name, attributes)
@log.debug("Running Chef Client for #{node_name} (#{instance.dns_name})")
ShellCmd.run("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{DPLOY_CONFIG['ec2_ssh_key_path']} ubuntu@#{instance.dns_name} sudo chef-client", @log)
@log.completion("Completed",{:status => "Success"})
end
rescue
@log.error("#{$!}")
@log.completion("Failed",{:status => "failure"})
end
end
|