Skip to content

Instantly share code, notes, and snippets.

@juliedavila
Created July 8, 2015 17:46
Show Gist options
  • Save juliedavila/5e2945a74891a3b20cd1 to your computer and use it in GitHub Desktop.
Save juliedavila/5e2945a74891a3b20cd1 to your computer and use it in GitHub Desktop.
Tier route tables for Ansible < 2
## Usage: lookup('tier_rt', 'dmz1')
import boto
import boto.vpc
import boto.ec2
from sets import Set
from ansible import utils
class LookupModule(object):
def __init__(self, basedir=None, **kwargs):
self.basedir = basedir
def run(self, terms, inject=None, **kwargs):
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
if isinstance(terms, basestring):
terms = [ terms ]
ret = []
try:
vpc = boto.vpc.VPCConnection()
except Exception, e:
utils.warnings('Boto authentication issue: %s' % e)
for term in terms:
eligible_subnets = vpc.get_all_subnets(filters={"tag:tier": term})
for subnet in eligible_subnets:
for rt in vpc.get_all_route_tables(filters={'association.subnet_id': subnet.id}):
ret.append(rt.id)
return Set(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment