Skip to content
This repository has been archived by the owner on Jun 28, 2019. It is now read-only.

Commit

Permalink
Allow for ec2_project_tag to be nil
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Valles committed Jun 10, 2015
1 parent 27a55ca commit 702b685
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ If running on EC2 the IAM instance profile credentials will be used if credentia

* project_tag

Cap-EC2 will look for a tag with this name when searching for instances that belong to this project.
Cap-EC2 will look for a value which matches the :application setting in your deploy.rb.
The tag name defaults to "Project" and must be set on your instances.
Cap-EC2 will look for a tag with this name when searching for instances that belong to this project.
Cap-EC2 will look for a value which matches the :application setting in your deploy.rb. The tag name
defaults to "Project". If this tag is not set on the instances, then use `set :ec2_project_tag, nil`.

* stages_tag

Expand Down
19 changes: 10 additions & 9 deletions lib/cap-ec2/ec2-handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,20 @@ def tag(tag_name)
end

def get_servers_for_role(role)
servers = []
@ec2.each do |_, ec2|
instances = ec2.instances
.filter(tag(project_tag), "*#{application}*")
.filter('instance-state-name', 'running')
servers << instances.select do |i|
@ec2.map do |_, ec2|
instances = project_tag ?
ec2.instances.filter(tag(project_tag), "*#{application}*") :
ec2.instances
filtered = instances.filter('instance-state-name', 'running')

filtered.select do |i|
instance_has_tag?(i, roles_tag, role) &&
instance_has_tag?(i, stages_tag, stage) &&
instance_has_tag?(i, project_tag, application) &&
(project_tag.nil? || instance_has_tag?(i, project_tag, application)) &&
(fetch(:ec2_filter_by_status_ok?) ? instance_status_ok?(i) : true)
end

end.flatten.sort_by { |s| s.tage["Name"] || ''}
end
servers.flatten.sort_by {|s| s.tags["Name"] || ''}
end

def get_server(instance_id)
Expand Down

0 comments on commit 702b685

Please sign in to comment.