Reusing existing EC2-Classic targeted Playbooks for EC2-VPC

25 views
Skip to first unread message

Sankalp Khare

unread,
Sep 23, 2014, 7:27:23 PM9/23/14
to ansible...@googlegroups.com
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.

--
Sankalp

Will Thames

unread,
Sep 23, 2014, 9:04:35 PM9/23/14
to ansible...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages