Last active
December 16, 2015 11:59
-
-
Save ianalexander/5431330 to your computer and use it in GitHub Desktop.
ec2-enc: A simple Puppet ENC written Python that uses EC2 Security Groups to generate node classifciations.
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
#! /usr/bin/python | |
# ec2-enc.py | |
# A simple Puppet ENC that converts EC2 Security Groups to Puppet classes | |
import boto.ec2 | |
import sys | |
# EC2Group: Puppet Class | |
GROUPS = {'default': 'role::default', 'web': 'role::web', 'app': 'role::app'} | |
conn = boto.ec2.connect_to_region( "us-east-1", | |
aws_access_key_id='key', | |
aws_secret_access_key='secret' ) | |
for r in conn.get_all_instances(): | |
for i in r.instances: | |
if i.public_dns_name: | |
# print "public: %s\tprivate: %s" % (i.public_dns_name, i.private_dns_name) | |
if i.private_dns_name.lower() == sys.argv[1].lower(): | |
# print "match! " + str(i.groups[0].name) | |
print "classes:\n %s:" % (GROUPS[i.groups[0].name]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment