Skip to content

Instantly share code, notes, and snippets.

@pfigue
Last active December 29, 2015 15:28
Show Gist options
  • Save pfigue/7690424 to your computer and use it in GitHub Desktop.
Save pfigue/7690424 to your computer and use it in GitHub Desktop.
Facter fact code and a python script to read some user defined AWS EC2 instance properties during provisioning.
# Invocation example:
#
# $ curl -s "http://169.254.169.254/latest/user-data/" > /tmp/test.yaml
# $ cat /tmp/test.yaml
# instance:
# flavor: application-server
# $ abc=$(cat /tmp/test.yaml | python ec2-user-data-parser.py instance flavor)
# $ echo $abc
# application-server
# $
import sys
import yaml
if __name__ == '__main__':
contents = sys.stdin.read()
document = yaml.load(contents)
for key in sys.argv[1:]:
try:
document = document[key]
except KeyError:
sys.exit(1)
sys.stdout.write(str(document))
sys.stdout.flush()
sys.exit(0)
# server_flavor.rb
Facter.add("server_flavor") do
setcode do
Facter::Util::Resolution.exec('/usr/bin/curl --silent "http://169.254.169.254/latest/user-data/" | /usr/bin/python /root/tools/ec2-user-data-parser.py instance flavor')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment