# Creating a RDS subnet group using with\_items + registered vpc variable

**URL:** <https://forum.ansible.com/t/creating-a-rds-subnet-group-using-with-items-registered-vpc-variable/16332>\
**Category:** Ansible Project\
**Created:** [September 25, 2014, 8:36am UTC](https://forum.ansible.com/t/creating-a-rds-subnet-group-using-with-items-registered-vpc-variable/16332 "2014-09-25T08:36:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Timo\_Ahokas](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Timo\_Ahokas](https://forum.ansible.com/u/Timo_Ahokas)\
**Post date:** [September 25, 2014, 8:36am UTC](https://forum.ansible.com/t/creating-a-rds-subnet-group-using-with-items-registered-vpc-variable/16332/1 "2014-09-25T08:36:17Z")

</div>

Hi,

I’m trying to use the rds\_subnet\_group module to create a subnet group with all the subnets defined in my VPC, but I’m having trouble finding a way of using the subnet ids from a registered vpc variable.

So, first I create a VPC & register the response:

- name: Create VPC  
local\_action:  
module: ec2\_vpc  
state: present  
subnets: …

route\_tables: …  
register: vpc

This works well and the result looks like:

TASK: [debug var=vpc] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“vpc”: {  
“changed”: true,  
“invocation”: {  
“module\_args”: “”,  
“module\_name”: “ec2\_vpc”  
},  
“subnets”: [  
{  
“az”: “eu-west-11”,  
“cidr”: “10.55.81.0/24”,  
“id”: “subnet-d1d21ea6”,  
“resource\_tags”: {  
“Environment”: “test”,  
“Name”: “test\_euw1a\_app”,  
}  
},

{ … } ] }

Now I’d like to use the subnet ids (subnets.id) in this response when creating a RDS subnet with all of them attached:

- name: Create DB subnet group  
local\_action:  
module: rds\_subnet\_group  
state: present  
name: “rds-sg”  
description: “rds-sg”  
subnets:
- “{{ item.id }}”  
with\_items: vpc.subnets

The problem is that if I have the with\_item on the same level of local\_action it seems to make N calls to rds\_subnet\_group (each with one of the ids) with fail with:  
msg: DB Subnet Group doesn’t meet availability zone coverage requirement. Please add subnets to cover at least 2 availability zones. Current coverage: 1

So I’d like to add all the subnets in one go (single call with all subnet ids defined for the “subnets” parameter). With\_items doesn’t seem to work when it’s nested on the same level with the other params (subnets/state) - instead I get the error:

fatal: [localhost → 127.0.0.1] =\> One or more undefined variables: ‘item’ is undefined

What would be the best way to use all the vpc.subnets.id values in a list and supply those to rds\_subnet\_group.subnets in one go?

Best regards,  
Timo

---

<div class="post-metadata">

**Author:** ![Timo\_Ahokas](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@Timo\_Ahokas](https://forum.ansible.com/u/Timo_Ahokas)\
**Post date:** [September 25, 2014, 12:20pm UTC](https://forum.ansible.com/t/creating-a-rds-subnet-group-using-with-items-registered-vpc-variable/16332/2 "2014-09-25T12:20:29Z")

</div>

Found the answer luckily by searching the groups.

Documented here if someone stumbles on the same thing (no need for with\_items):

subnets: “{{ vpc.subnets | map(attribute=‘id’) | list}}”

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [December 4, 2014, 4:01pm UTC](https://forum.ansible.com/t/creating-a-rds-subnet-group-using-with-items-registered-vpc-variable/16332/3 "2014-12-04T16:01:37Z")

</div>

It’s quite frustrating that the ‘rds\_subnet\_group’ produces too few debug info:

`

\< TASK: debug var=rds\_sg\_creation \>
