Last active
December 29, 2015 15:28
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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