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

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. :slight_smile: (https://groups.google.com/forum/#!searchin/ansible-project/doesn$27t$20seem$20to$20/ansible-project/ZF07H5mBofo/WIBtqtBtvFQJ)

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

Thanks a bunch Lester,

Don’t know, how I have missed it :slight_smile: