@@ -0,0 +1,1183 @@
+# (c) 2015, Jon Hadfield %3Cjon@lessknown.co.uk%3E%0A%22%22%22%0ADescription: This lookup takes an AWS region and a list of one or more%0Asecurity Group Names and returns a list of matching security Group IDs. %0A%0AExample Usage:%0A%7B%7B lookup('aws_secgroup_ids_from_names', ('eu-west-1', %5B'nginx_group', 'mysql_group'%5D)) %7D%7D%0A%22%22%22%0Afrom __future__ import (absolute_import, division, print_function)%0A__metaclass__ = type%0A%0Aimport os%0Aimport codecs%0A%0Afrom ansible.errors import *%0Afrom ansible.plugins.lookup import LookupBase%0A%0Atry:%0A    import boto%0A    import boto.ec2%0Aexcept ImportError:%0A    raise AnsibleError(%22aws_secgroup_ids_from_names lookup cannot be run without boto installed%22)%0A%0Aclass LookupModule(LookupBase):%0A%0A    def run(self, terms, variables=None, **kwargs):%0A        if isinstance(terms, basestring):%0A            terms = %5Bterms%5D%0A        sg_list = %5B%5D%0A        region = terms%5B0%5D%0A        group_names = terms%5B1%5D%0A        conn = boto.ec2.connect_to_region(region)%0A        for group_name in group_names:%0A            filters = %7B'group_name': group_name%7D%0A            sg = conn.get_all_security_groups(filters=filters)%0A            if sg and sg%5B0%5D:%0A                sg_list.append(sg%5B0%5D.id)%0A        return sg_list%0A

add initial secgroup ids from names lookup.