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

Allow for ec2_project_tag to be nil #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
servers.flatten.sort_by {|s| s.tags["Name"] || ''}
end.flatten.sort_by { |s| s.tags["Name"] || ''}
end

def get_server(instance_id)
Expand Down