# How to specify the Security Group IDs for VPC based EC2 instance creation

**URL:** <https://forum.ansible.com/t/how-to-specify-the-security-group-ids-for-vpc-based-ec2-instance-creation/13702>\
**Category:** Ansible Project\
**Created:** [October 17, 2013, 8:24am UTC](https://forum.ansible.com/t/how-to-specify-the-security-group-ids-for-vpc-based-ec2-instance-creation/13702 "2013-10-17T08:24:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sundar1](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@Sundar1](https://forum.ansible.com/u/Sundar1)\
**Post date:** [October 17, 2013, 8:24am UTC](https://forum.ansible.com/t/how-to-specify-the-security-group-ids-for-vpc-based-ec2-instance-creation/13702/1 "2013-10-17T08:24:06Z")

</div>

Sorry,

I had looked into the Doc also the group discussions but couldn’t locate this simple piece of info.

I’m trying to create a EC2 instance in VPC with few security groups assigned to it. But am not able to assign the security groups as now.

This is what I used and it assigns default security group.

tasks:

- name: Launch instance  
local\_action: ec2 keypair={{ ec2\_keypair\_name }} instance\_type={{ ec2\_instance\_type }} image={{ ec2\_ami\_id }} wait=yes region={{ ec2\_region }} aws\_access\_key={{ aws\_access\_key }} aws\_secret\_key={{ aws\_secret\_key }} vpc\_subnet\_id={{ subnet\_id }}  
register: ec2

When I try to assign (like we do for plain ec2), like this,

tasks:

- name: Launch instance  
local\_action: ec2 keypair={{ ec2\_keypair\_name }} group={{ ec2\_security\_group\_name }} instance\_type={{ ec2\_instance\_type }} image={{ ec2\_ami\_id }} wait=yes region={{ ec2\_region }} aws\_access\_key={{ aws\_access\_key }} aws\_secret\_key={{ aws\_secret\_key }} vpc\_subnet\_id={{ subnet\_id }}  
register: ec2

and it throws

failed: [12.0.0.11] =\> {“failed”: true}  
msg: InvalidParameterCombination: The parameter groupName cannot be used with the parameter subnet

FATAL: all hosts have already failed – aborting

Could you help me with the correct param name to be used for specifying the security group ids (In Boto - it’s security group ids not names in case of VPC, i believe) ? Thanks.

**Note**

Plz, lets not get into using env variables for aws\_access\_key & aws\_secret\_key. That’s a different story altogether. 🙂 ([https://groups.google.com/forum/#!searchin/ansible-project/doesn$27t$20seem$20to$20/ansible-project/ZF07H5mBofo/WIBtqtBtvFQJ](https://groups.google.com/forum/#!searchin/ansible-project/doesn$27t$20seem$20to$20/ansible-project/ZF07H5mBofo/WIBtqtBtvFQJ))

---

<div class="post-metadata">

**Author:** ![Lester\_Wade](https://avatars.discourse-cdn.com/v4/letter/l/97f17d/32.png) [@Lester\_Wade](https://forum.ansible.com/u/Lester_Wade)\
**Post date:** [October 17, 2013, 9:13am UTC](https://forum.ansible.com/t/how-to-specify-the-security-group-ids-for-vpc-based-ec2-instance-creation/13702/2 "2013-10-17T09:13:19Z")

</div>

Hi Sundar,

If you look at the module documentation there is the group\_id parameter which takes security group ID’s. This should work for you, providing you pass is a group ID relative to your VPC.

Lester

---

<div class="post-metadata">

**Author:** ![Sundar1](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@Sundar1](https://forum.ansible.com/u/Sundar1)\
**Post date:** [October 17, 2013, 10:38am UTC](https://forum.ansible.com/t/how-to-specify-the-security-group-ids-for-vpc-based-ec2-instance-creation/13702/3 "2013-10-17T10:38:42Z")

</div>

Thanks a bunch Lester,

Don’t know, how I have missed it 🙂
