Skip to content

Instantly share code, notes, and snippets.

@ptierno
Forked from yureative/ec2_tags.rb
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptierno/f1a394bcf86a837435e3 to your computer and use it in GitHub Desktop.
Save ptierno/f1a394bcf86a837435e3 to your computer and use it in GitHub Desktop.
require 'json'
Ohai.plugin(:EC2Tags) do
provides "ec2/tags"
depends "ec2"
collect_data do
region = ec2['placement_availability_zone'].chop
instance_id = ec2['instance_id']
so = shell_out("aws ec2 describe-tags --region #{region} --filters Name=resource-type,Values=instance Name=resource-id,Values=#{instance_id}")
if so.exitstatus == 0
ec2[:tags] = JSON.parse(so.stdout)['Tags'].map {|tag| {tag['Key'] => tag['Value']}}.inject(Mash.new, :merge)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment