Skip to content

Instantly share code, notes, and snippets.

@zarmstrong
Forked from drohr/ec2tags.rb
Last active July 4, 2016 19:03
Show Gist options
  • Save zarmstrong/6893172 to your computer and use it in GitHub Desktop.
Save zarmstrong/6893172 to your computer and use it in GitHub Desktop.
replaces spaces with pipes to take into account non-word (\w) characters in key or value.
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