# Dynamic list variable

**URL:** <https://forum.ansible.com/t/dynamic-list-variable/15568>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [June 27, 2014, 5:29pm UTC](https://forum.ansible.com/t/dynamic-list-variable/15568 "2014-06-27T17:29:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmccarthy](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mmccarthy](https://forum.ansible.com/u/mmccarthy)\
**Post date:** [June 27, 2014, 5:29pm UTC](https://forum.ansible.com/t/dynamic-list-variable/15568/1 "2014-06-27T17:29:41Z")

</div>

Hi All,

I am attempting to create an AWS VPC and AWS DB subnet group within an Ansible play. My problem is that I need to know the subnet ids in order to create a DB subnet group. I have registered the results of the ec2\_vpc module. This gives me access to the subnets and their ids but does not seem to be ordered. I have 6 subnets, 2 of which are DB subnets. They are marked with a tag. I need to get a list of 2 subnet ids to pass to the db\_subnets module. Can anyone suggest a good way to do this? I tried doing a set\_fact with a “with\_items” and “when” but that gives only a single subnet. Of course I don’t know what the subnet ids are until after the VPC is created. I would really rather not have to manually add these in and run another play.

Thanks,  
Michael
