Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. require 'json'
  2.  
  3. Ohai.plugin(:EC2Tags) do
  4. provides "ec2/tags"
  5.  
  6. depends "ec2"
  7.  
  8. collect_data do
  9. region = ec2['placement_availability_zone'].chop
  10. instance_id = ec2['instance_id']
  11.  
  12. so = shell_out("aws ec2 describe-tags --region #{region} --filters Name=resource-type,Values=instance Name=resource-id,Values=#{instance_id}")
  13. if so.exitstatus == 0
  14. ec2[:tags] = JSON.parse(so.stdout)['Tags'].map {|tag| {tag['Key'] => tag['Value']}}.inject(Mash.new, :merge)
  15. end
  16. end
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement