Last active
December 11, 2015 12:08
-
-
Save richleland/4598118 to your computer and use it in GitHub Desktop.
Python ENC and manifest that use AWS tags as classifiers
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/env python | |
import yaml | |
import sys | |
from boto.ec2.connection import EC2Connection | |
ec2 = EC2Connection() | |
fqdn = sys.argv[1] | |
hostname = fqdn.split('.')[0] | |
for res in ec2.get_all_instances(filters={'tag:Name': hostname}): | |
for inst in res.instances: | |
print yaml.safe_dump({ | |
'parameters': { | |
'ec2_id': inst.id, | |
'ec2_groups': [group.name for group in inst.groups], | |
'ec2_public_dns_name': inst.public_dns_name, | |
'ec2_private_dns_name': inst.private_dns_name, | |
'ec2_state': inst.state, | |
'ec2_key_name': inst.key_name, | |
'ec2_instance_type': inst.instance_type, | |
'ec2_launch_time': inst.launch_time, | |
'ec2_image_id': inst.image_id, | |
'ec2_placement': inst.placement, | |
'ec2_kernel': inst.kernel, | |
'ec2_architecture': inst.architecture, | |
'ec2_hypervisor': inst.hypervisor, | |
'ec2_ami_launch_index': inst.ami_launch_index, | |
'ec2_private_ip_address': inst.private_ip_address, | |
'ec2_ip_address': inst.ip_address, | |
'ec2_root_device_name': inst.root_device_name, | |
'ec2_root_device_type': inst.root_device_type, | |
'ec2_tags': dict(inst.tags), | |
'groups': inst.tags['groups'].split(','), | |
'environment': inst.tags['environment'], | |
} | |
}) |
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
node default { | |
if $::ec2_tags { | |
if $::ec2_tags['course-server'] and $::ec2_tags['group'] { | |
class { 'group::course_server': | |
course_name => "${ec2_tags['group']}", | |
} | |
} elsif $::group { | |
role::include { 'base': } | |
role::include { $group: } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://docs.puppetlabs.com/guides/external_nodes.html