Skip to content

Instantly share code, notes, and snippets.

@misakwa
Forked from zarmstrong/ec2tags.rb
Created September 1, 2014 15:32
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 misakwa/2c225c64302c02f8706f to your computer and use it in GitHub Desktop.
Save misakwa/2c225c64302c02f8706f 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