This repository has been archived by the owner on Jun 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathec2_hack.rb
61 lines (53 loc) · 1.66 KB
/
ec2_hack.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Fact: ec2_<EC2 INSTANCE DATA>
#
# Purpose:
# Returns info retrieved in bulk from the EC2 API. The names of these facts
# should be self explanatory, and they are otherwise undocumented. The full
# list of these facts is: ec2_ami_id, ec2_ami_launch_index,
# ec2_ami_manifest_path, ec2_block_device_mapping_ami,
# ec2_block_device_mapping_ephemeral0, ec2_block_device_mapping_root,
# ec2_hostname, ec2_instance_id, ec2_instance_type, ec2_kernel_id,
# ec2_local_hostname, ec2_local_ipv4, ec2_placement_availability_zone,
# ec2_profile, ec2_public_hostname, ec2_public_ipv4,
# ec2_public_keys_0_openssh_key, ec2_reservation_id, and ec2_security_groups.
#
# Resolution:
# Directly queries the EC2 metadata endpoint.
#
require 'facter/ec2/rest' unless defined?(Facter::EC2)
Facter.define_fact(:ec2_metadata) do
define_resolution(:rest) do
confine do
Facter.value(:virtual).match /^(xen|kvm|docker)/
end
@querier = Facter::EC2::Metadata.new
confine do
@querier.reachable?
end
setcode do
@querier.fetch
end
end
end
Facter.define_fact(:ec2_userdata) do
define_resolution(:rest) do
confine do
Facter.value(:virtual).match /^(xen|kvm)/
end
@querier = Facter::EC2::Userdata.new
confine do
@querier.reachable?
end
setcode do
@querier.fetch
end
end
end
# The flattened version of the EC2 facts are deprecated and will be removed in
# a future release of Facter.
if (ec2_metadata = Facter.value(:ec2_metadata))
ec2_facts = Facter::Util::Values.flatten_structure("ec2", ec2_metadata)
ec2_facts.each_pair do |factname, factvalue|
Facter.add(factname, :value => factvalue)
end
end