Skip to content

Instantly share code, notes, and snippets.

@Seraf
Last active August 29, 2015 14:10
Show Gist options
  • Save Seraf/a4353d507dae0f184989 to your computer and use it in GitHub Desktop.
Save Seraf/a4353d507dae0f184989 to your computer and use it in GitHub Desktop.
ec2 tags to facts. It requires aws-cli (pip install aws-cli)
require 'facter'
require 'json'
instance_id = Facter.value("ec2_instance_id")
region = Facter.value("ec2_placement_availability_zone")[0..-2]
tags = Facter::Util::Resolution.exec("/usr/local/bin/aws ec2 describe-tags --filters \"Name=resource-id,Values=#{instance_id}\" --region #{region} | cut -f 4-")
parsed_tags = JSON.parse(tags)
parsed_tags['Tags'].each do |tag|
Facter.add("ec2_tag_#{tag["Key"]}") do
setcode do
"#{tag["Value"]}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment