|
#Set proxy before we try to talk to AWS API |
|
ENV["http_proxy"] ||= 'http://proxy:port' |
|
ENV["https_proxy"] ||= 'http://proxy:port' |
|
ENV["NO_PROXY"] ||= '127.0.0.1, localhost, 169.254.169.254' |
|
|
|
#Make 1 EC2 API call and put the output on a dot file in /tmp/.tags |
|
|
|
region = Facter.value('region') |
|
instanceid = Facter.value('instanceid') |
|
%x{/usr/bin/aws --region #{region} --output text ec2 describe-instances --instance-ids #{instanceid} | grep "TAGS" | awk '{ print $2 " " $3 " " $4}'| tr [:upper:] [:lower:] > /tmp/.tags }.chomp |
|
|
|
#Create the fact from the NAME (EC2) TAG |
|
Facter.add("tag_name") do |
|
setcode do |
|
%x{/bin/egrep -iw "Name" /tmp/.tags | /bin/awk '{ print $2 }'}.chomp |
|
end |
|
end |
|
|
|
#Create the fact from the SDLC (EC2) TAG |
|
Facter.add("tag_sdlc") do |
|
setcode do |
|
%x{/bin/egrep -iw "SDLC" /tmp/.tags | /bin/awk '{ print $2 }'}.chomp |
|
end |
|
end |
|
|
|
##Create the fact from the OWNER (EC2) TAG |
|
Facter.add("tag_owner") do |
|
setcode do |
|
%x{/bin/egrep -iw "OWNER" /tmp/.tags | /bin/awk '{ print $2 " " $3 }'}.chomp |
|
end |
|
end |
|
|
|
##Create the fact from the PURPOSE (EC2) TAG |
|
Facter.add("tag_purpose") do |
|
setcode do |
|
%x{/bin/egrep -iw "PURPOSE" /tmp/.tags | /bin/awk '{ print $2 }'}.chomp |
|
end |
|
end |
|
|
|
#Create the fact from the role (EC2) TAG |
|
Facter.add("tag_role") do |
|
setcode do |
|
%x{/bin/egrep -iw "^role" /tmp/.tags | /bin/awk '{ print $2 }'}.chomp |
|
end |
|
end |
|
|
|
#Creates and populates the AWS region fact |
|
Facter.add("region") do |
|
setcode do |
|
Facter::Util::Resolution.exec('/usr/bin/curl -sf http://169.254.169.254/latest/dynamic/instance-identity/document|grep region|awk -F\" \'{print $4}\'') |
|
end |
|
end |
|
|
|
#Creates and populates the instanceid fact |
|
Facter.add("instancetype") do |
|
setcode do |
|
Facter::Util::Resolution.exec('/usr/bin/curl -sf http://169.254.169.254/latest/meta-data/instance-type;echo ""') |
|
end |
|
end |
|
|
|
#Creates and populates the instanceid fact |
|
Facter.add("instanceid") do |
|
setcode do |
|
Facter::Util::Resolution.exec('/usr/bin/curl -sf http://169.254.169.254/latest/meta-data/instance-id;echo ""') |
|
end |
|
end |
|
|
|
#Creates a fact which displays the version (JUST THE VERSION) of the awscli |
|
Facter.add('awscliver') do |
|
setcode do |
|
`/usr/bin/aws --version 2>&1`[/aws-cli\/([^ ]+) /, 1] |
|
end |
|
end |