# provisioning multiple ec2 instances to multiple subnets and dealing with unmatching numbers

**URL:** <https://forum.ansible.com/t/provisioning-multiple-ec2-instances-to-multiple-subnets-and-dealing-with-unmatching-numbers/24004>\
**Category:** Ansible Project\
**Created:** [March 18, 2017, 12:37am UTC](https://forum.ansible.com/t/provisioning-multiple-ec2-instances-to-multiple-subnets-and-dealing-with-unmatching-numbers/24004 "2017-03-18T00:37:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoash\_ben\_tulila](https://avatars.discourse-cdn.com/v4/letter/y/9dc877/32.png) [@yoash\_ben\_tulila](https://forum.ansible.com/u/yoash_ben_tulila)\
**Post date:** [March 18, 2017, 12:37am UTC](https://forum.ansible.com/t/provisioning-multiple-ec2-instances-to-multiple-subnets-and-dealing-with-unmatching-numbers/24004/1 "2017-03-18T00:37:06Z")

</div>

Hello,

I am building a provisioning system that will be receiving parameters from a jenkins job.

1. I want to have a single playbook from where I can create new ec2 instances for both ec2-classic and vpc, though I can live with 2 different playbook in case it won’t work otherwise.

2. I want for example, to launch 6 instances spread across 3 subnet-ids given, within 1 run of playbook.

3. I want for example, to launch 3 instances from 6 subnet-ids given, within 1 run of playbook.

4. when I use “with\_items” and pass an array of say, 10 subnets, then 10 instances will be created. I wantcto be able to decide how many instances eventually run

5. when using " {{ var | random }} → I was able to retrieve a subnet/zone randomly, but it would create 10 instances with the same subnet (which was picked randomly but didn’t change between the iterations).

6. I didn’t really get into “count\_tag” and “exact\_count” because from what I read these parameters decide how many instances of the decided tag will run, eliminating other (and I don’t want to allow any kind of instance termination in this scope).

I thought of using the “until” option but wasn’t able to find any way to know how many instances have been created, like some value that gets incremented every run.

a valid “until” statement can be: "ec2.instances length = desired\_number\_of\_instances

your help will be highly appreciated.
