# Constructing a List.

**URL:** <https://forum.ansible.com/t/constructing-a-list/18819>\
**Category:** Ansible Project\
**Created:** [July 22, 2015, 8:57am UTC](https://forum.ansible.com/t/constructing-a-list/18819 "2015-07-22T08:57:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![runmyjobs](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@runmyjobs](https://forum.ansible.com/u/runmyjobs)\
**Post date:** [July 22, 2015, 8:57am UTC](https://forum.ansible.com/t/constructing-a-list/18819/1 "2015-07-22T08:57:34Z")

</div>

Hi,

Using a ‘shell’ task I’m obtaining a list of subnet id’s from Amazon, these subnet id’s I want to pass in to the ec2\_elb\_lb task.  
However this task accepts a list for Subnets only, so is there a way to dynamically construct a list out of the id’s that I obtained?

Thanks,  
Nico

---

<div class="post-metadata">

**Author:** ![jon2](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@jon2](https://forum.ansible.com/u/jon2)\
**Post date:** [July 22, 2015, 5:05pm UTC](https://forum.ansible.com/t/constructing-a-list/18819/2 "2015-07-22T17:05:09Z")

</div>

Hi,

Instead of using shell, you could use a lookup plugin that will query the ids by name for you.  
So when creating the subnets, give them a name and also store them in a list, e.g.  
mysubnets:

- subnet1
- subnet2

You can then define your ELB like this:

ec2\_elb\_lb:  
…  
subnets: “{{ lookup(‘aws\_subnet\_ids\_from\_names’, (region, mysubnets)) }}”

Where region is a variable containing a region name, i.e. ‘eu-west-1’.  
This will return a list of the subnet ids that the ec2\_elb\_lb module expects.  
To use this, just copy the lookup plugin from [here](https://github.com/jonhadfield/ansible-lookups) into a directory called lookup\_plugins in the root of your project.

Jon

---

<div class="post-metadata">

**Author:** ![Igor\_Homyakov](https://avatars.discourse-cdn.com/v4/letter/i/f4b2a3/32.png) [@Igor\_Homyakov](https://forum.ansible.com/u/Igor_Homyakov)\
**Post date:** [July 23, 2015, 7:26am UTC](https://forum.ansible.com/t/constructing-a-list/18819/3 "2015-07-23T07:26:30Z")

</div>

Hi Jon,

That is awesome. Thank you for sharing.

-- Best, Igor
