Skip to content

Instantly share code, notes, and snippets.

@sh4t
Forked from zarmstrong/ec2tags.rb
Created July 30, 2014 17:02
Show Gist options
  • Save sh4t/2300f43738a9d2a811e7 to your computer and use it in GitHub Desktop.
Save sh4t/2300f43738a9d2a811e7 to your computer and use it in GitHub Desktop.
require 'facter'
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("ec2dtag --filter \"resource-id=#{instance_id}\" --region #{region} | cut -f 4-|awk 'BEGIN{FS=\" \";OFS=\"|\"} {$1=$1; print $0}'")
tags.scan(/(.*)\|+(.*)/) do |key, value|
fact = "ec2_tag_#{key}"
Facter.add(fact) { setcode { value } }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment