Skip to content

Instantly share code, notes, and snippets.

@drohr
Created February 27, 2013 15:29
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save drohr/5048751 to your computer and use it in GitHub Desktop.
Save drohr/5048751 to your computer and use it in GitHub Desktop.
Hack to get ec2 tags to facter.
require 'facter'
instance_id = Facter::Util::Resolution.exec("ec2-metadata -i | awk '{print $2}'")
tags = Facter::Util::Resolution.exec("ec2-describe-tags --region eu-west-1 --filter \"resource-id=#{instance_id}\" | cut -f 4-")
tags.scan(/(\w+)\s+(\w+)/) do |key, value|
fact = "ec2_tag_#{key}"
Facter.add(fact) { setcode { value } }
end
@rafaelfelix
Copy link

Great job! Thanks a lot!

Check my version when you can. I've added support to tags with spaces and special chars in between: https://gist.github.com/rafaelfelix/5937611

@zarmstrong
Copy link

https://gist.github.com/zarmstrong/6893172

I've forked this to take into account non-word (\w) characters in key or value. It replaces the field separator " " (space) with | (pipe).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment