ruby - AWS - get autoscaling names for use with Capistrano -
i trying setup remote deployment capistrano on amazon cloud.
the idea : ssh random machine of autoscaling group , want deploy other machines there. in order need names of other instances can define capistrano servers want deploy to
i have installed ruby sdk cannot figure out best way retrieve instances names (taking advantage on vpn).
i have 2 possibilities : either find instances tags (i have tagged them "production") or id of autoscaling group.
i don't want use other "big guns" chef, etc.
after reading documentation
two strategies : retrieve dns names autoscaling group or tags
by tags
ec2 = aws::ec2::client.new instances_tagged = ec2.describe_instances( dry_run: false, filters: [ { name: 'tag:environment', values: ['production'], }, { name: 'tag:stack', values: ['rails'], } ], ) dns_tagged = instances_tagged.reservations[0].instances.map(&:private_dns_name)
by autoscaling group
as = aws::autoscaling::client.new instances_of_as = as.describe_auto_scaling_groups( auto_scaling_group_names: ['autoscaling-group-name'], max_records: 1, ).auto_scaling_groups[0].instances if instances_of_as.empty? autoscaling_dns = [] else instances_ids = instances_of_as.map(&:instance_id) autoscaling_dns = instance_ids.map |instance_id| ec2.instances[instance_id].private_dns_name end end
Comments
Post a Comment