Skip to content

Instantly share code, notes, and snippets.

@jrnt30
Forked from mlehner616/ec2tags.rb
Last active August 29, 2015 14:16
Show Gist options
  • Save jrnt30/69bd8ce9a6356bc87405 to your computer and use it in GitHub Desktop.
Save jrnt30/69bd8ce9a6356bc87405 to your computer and use it in GitHub Desktop.
require 'facter'
require 'json'
if Facter.value("ec2_instance_id") != nil
instance_id = Facter.value("ec2_instance_id")
region = Facter.value("ec2_placement_availability_zone")[0..-2]
tags = Facter::Util::Resolution.exec("aws ec2 describe-tags --region #{region} --filters \"Name=resource-id,Values=#{instance_id}\" --query 'Tags[*].{value:Value,key:Key}'")
parsed_tags = JSON.parse(tags)
parsed_tags.each do |tag|
fact = "ec2_tag_#{tag["key"]}"
Facter.add(fact) { setcode { tag["value"] } }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment