# EC2 Ansible Module - Multiple Security Groups?

**URL:** <https://forum.ansible.com/t/ec2-ansible-module-multiple-security-groups/13203>\
**Category:** Ansible Project\
**Created:** [July 27, 2013, 1:23am UTC](https://forum.ansible.com/t/ec2-ansible-module-multiple-security-groups/13203 "2013-07-27T01:23:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shih\_Oon\_Liong1](https://avatars.discourse-cdn.com/v4/letter/s/ecd19e/32.png) [@Shih\_Oon\_Liong1](https://forum.ansible.com/u/Shih_Oon_Liong1)\
**Post date:** [July 27, 2013, 1:23am UTC](https://forum.ansible.com/t/ec2-ansible-module-multiple-security-groups/13203/1 "2013-07-27T01:23:16Z")

</div>

Has anyone been able to provision EC2 instances with multiple security groups associated with one instance?

When I do something like

- name: launch  
local\_action:  
module: ec2  
region: us-west-2  
keypair: mykey  
group\_id: [sg-xx, sg-yy, sg-zz]  
instance\_type: t1.micro  
image: ami-70f96e40  
wait: yes  
wait\_timeout: 3500  
count: 2  
instance\_tags: ‘{“Name”:“stuff”}’  
register: ec2batch

But the final instance that gets created only has one security group associated with it.

I was using group\_id because “group” did not seem to find my security group. When I did

- name: launch socialkit settings-scrape instances  
local\_action:  
module: ec2  
region: us-west-2  
keypair: memelabs  
group: [mygroup1, mygroup2, mygroup3]  
instance\_type: t1.micro  
image: ami-70f96e40  
wait: yes  
wait\_timeout: 3500

count: 2  
instance\_tags: ‘{“Name”:“stuff”}’  
register: ec2batch

It would give me an error that unable to find security group by that name.

My env:  
Ansible 1.2.1  
Boto 2.9.9

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 27, 2013, 2:48am UTC](https://forum.ansible.com/t/ec2-ansible-module-multiple-security-groups/13203/2 "2013-07-27T02:48:25Z")

</div>

Per the docs it’s “group”, not group\_id.

I’ll defer the question of why it might not find your group to other EC2 experts.

---

<div class="post-metadata">

**Author:** ![John\_Jarvis](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@John\_Jarvis](https://forum.ansible.com/u/John_Jarvis)\
**Post date:** [July 27, 2013, 3:47pm UTC](https://forum.ansible.com/t/ec2-ansible-module-multiple-security-groups/13203/3 "2013-07-27T15:47:00Z")

</div>

group:  
description:

- security group (or list of groups) to use with the instance  
required: false  
default: null  
aliases: [‘groups’]  
group\_id:  
version\_added: “1.1”  
description:
- security group id to use with the instance  
required: false  
default: null  
aliases: 

The “group\_id” argument (for the sg### aws identifiier) only accepts a single ID as a string where the “group” argument (the human friendly name of the group) will take either a string or list.

It does seem inconstant, if we are allowing a list of items for the singular “group” we might as well for the “group\_id” I think.  
If it’s having trouble looking up your group by name it’s likely you have bigger problems, maybe check that you are using the correct region?

-John

---

<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:** [July 27, 2013, 4:48pm UTC](https://forum.ansible.com/t/ec2-ansible-module-multiple-security-groups/13203/4 "2013-07-27T16:48:52Z")

</div>

There is a PR that I expect will soon be merged which fixes the list of groups or group id’s with the ec2 module. I would link to it but travelling and using the mobile right now 🙂
