# Reusing existing EC2-Classic targeted Playbooks for EC2-VPC

**URL:** <https://forum.ansible.com/t/reusing-existing-ec2-classic-targeted-playbooks-for-ec2-vpc/16313>\
**Category:** Ansible Project\
**Created:** [September 23, 2014, 11:27pm UTC](https://forum.ansible.com/t/reusing-existing-ec2-classic-targeted-playbooks-for-ec2-vpc/16313 "2014-09-23T23:27:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sankalp\_Khare](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@Sankalp\_Khare](https://forum.ansible.com/u/Sankalp_Khare)\
**Post date:** [September 23, 2014, 11:27pm UTC](https://forum.ansible.com/t/reusing-existing-ec2-classic-targeted-playbooks-for-ec2-vpc/16313/1 "2014-09-23T23:27:23Z")

</div>

Hi,

Over the past few months using Ansible, I’ve accumulated a handy bunch of playbooks which create different varieties of servers. The top-level directory looks like this :

modular-role-based-playbooks

> – [-rw-r–r–] create-bare-micro-instance-amazon.yml

> – [-rw-r–r–] create-captcha-server.yml  
> – [-rw-r–r–] create-sandbox-server.yml

> – [-rw-r–r–] create-support.yml

> – [-rw-r–r–] create-test-machine-for-interview.yml  
> – [-rw-r–r–] create-web.yml  
> – [-rw-r–r–] create-webdriver.yml

> – [-rw-r–r–] create-worker.yml  
> – [drwxr-xr-x] envs  
> – [drwxr-xr-x] group\_vars  
> – [lrwxr-xr-x] inventories → …/inventories  
> – [drwxr-xr-x] make-playbook-with-roles  
> – [drwxr-xr-x] roles  
> `-- [drwxr-xr-x] templates

How must I proceed so that with minimum redundancy I can create the same types of servers inside VPC as well?

I understand that the ec2 module requires extra parameters passed when the instance is to be created inside VPC, so is it possible to have a conditional that disables/enables these parameters?

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![willthames](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@willthames](https://forum.ansible.com/u/willthames)\
**Post date:** [September 24, 2014, 1:04am UTC](https://forum.ansible.com/t/reusing-existing-ec2-classic-targeted-playbooks-for-ec2-vpc/16313/2 "2014-09-24T01:04:35Z")

</div>

For your setup, I’d recommend either having a role to create an instance, or a single playbook that creates an instance and later kicks off ansible-pull. You really shouldn’t have to be changing your use of the ec2 module across multiple files.

I would just choose values for the required variables so that they work in either environment.

Let’s say you have a group for VPC hosts (you might have multiple groups for multiple VPCs) - and one for non VPC hosts

Then in the vpc1.yml, set things like vpc\_subnet\_id (looking at the docs that’s the only one you’ll likely need)  
In nonvpc.yml, have vpc\_subnet\_id: “”

And then when you use the ec2 module, pass  
vpc\_subnet\_id: “{{vpc\_subnet\_id}}”

Will
