Skip to content

Instantly share code, notes, and snippets.

@ianalexander
Last active December 16, 2015 11:59
Show Gist options
  • Save ianalexander/5431330 to your computer and use it in GitHub Desktop.
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.
#! /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