Skip to content

Instantly share code, notes, and snippets.

@dragosboca
Forked from rafaelfelix/ec2tags.rb
Last active April 27, 2018 21:43
Show Gist options
  • Save dragosboca/e4d7b65f3892fd11e456 to your computer and use it in GitHub Desktop.
Save dragosboca/e4d7b65f3892fd11e456 to your computer and use it in GitHub Desktop.
require 'facter'
require 'aws-sdk'
if Facter.value("ec2_instance_id") != nil
instance_id = Facter.value("ec2_instance_id")
region = Facter.value("ec2_placement_availability_zone")[0..-2]
ec2 = Aws::EC2::Client.new(region:region)
instance = ec2.describe_instances(instance_ids:[instance_id])
tags = instance.reservations[0].instances[0].tags
tags.each do |tag|
fact = "ec2_tag_#{tag["key"]}"
Facter.add(fact) { setcode { tag["value"] } }
end
Facter.add("ec2_region") { setcode { region } }
end
@tktucker
Copy link

tktucker commented Apr 8, 2015

How do I can this ruby file from Puppet? I don't see any of the "c2_tag_#" data in faster -p either.
Thanks

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