# ec2\_vpc :: Different output format when using with\_items

**URL:** <https://forum.ansible.com/t/ec2-vpc-different-output-format-when-using-with-items/21238>\
**Category:** Ansible Project\
**Created:** [April 21, 2016, 9:41pm UTC](https://forum.ansible.com/t/ec2-vpc-different-output-format-when-using-with-items/21238 "2016-04-21T21:41:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gustavo\_Aguiar](https://avatars.discourse-cdn.com/v4/letter/g/45deac/32.png) [@Gustavo\_Aguiar](https://forum.ansible.com/u/Gustavo_Aguiar)\
**Post date:** [April 21, 2016, 9:41pm UTC](https://forum.ansible.com/t/ec2-vpc-different-output-format-when-using-with-items/21238/1 "2016-04-21T21:41:49Z")

</div>

Hi All,

I have noticed a “strange” behaviour in one of my playbooks that use the ec2\_vpc module. After changing how to input data the output format changed.

I’m not sure if this is expected or not but couldn’t find any documentation around it. Perhaps someone encountered the same scenario before ?

Let me explain.

I had a playbook to create a VPC that I was using variables for CIDR Block, Internet Gateway (yes/no) and two Tags (Name and Environment). After running the playbook I was able to retrieve the vpc\_id from {{ ec2\_vpc\_out.vpc\_id }}.

**Request — without using with\_items:**

35 # create the VPC  
36 - name: VPC | Create the required VPC  
37 ec2\_vpc:  
38 aws\_access\_key: “{{ aws\_access\_key }}”  
39 aws\_secret\_key: “{{ aws\_secret\_key }}”  
40 region: “{{ aws\_region }}”  
41 state: present  
42 cidr\_block: “{{ aws\_vpc\_cidr\_block }}”  
43 resource\_tags:  
44 Name: “{{ aws\_vpc\_name }}”  
45 Environment: “{{ aws\_vpc\_subnet\_envname }}”  
46 internet\_gateway: “{{ aws\_vpc\_internet\_gateway }}”  
47 subnets:  
48 “{{ my\_subnets }}”  
49 route\_tables:  
50 “{{ aws\_route\_table\_info }}”  
51 register: ec2\_vpc\_out

**Response —**  **without using with\_items** \*\*:\*\*

ok: [localhost] =\> {  
“msg”: {  
“changed”: false,  
“igw\_id”: “igw-dddddddd”,  
“subnets”: [  
{  
“az”: “ap-southeast-2a”,  
“cidr”: “10.125.0.0/24”,  
“id”: “subnet-bbbbbbbb”,  
“resource\_tags”: {  
“Environment”: “Test",  
“Name”: “Subnet-Test-A",  
“TierName”: “Test",  
“TierType”: “Test"  
}  
},

(…)

],  
“vpc”: {  
“cidr\_block”: “10.125.0.0/16”,  
“dhcp\_options\_id”: “dopt-99999999”,  
“id”: “vpc-55555555”,  
“region”: “ap-southeast-2”,  
“state”: “available”  
},  
“vpc\_id”: “vpc-55555555”  
}  
}

I changed this playbook to read those variables for CIDR Block, Internet Gateway (yes/no) and two Tags (Name and Environment) from a dictionary and after this the output format changed.

**Dictionary:**

19 aws\_vpc\_info:  
20 - cidr\_block: “{{ aws\_vpc\_cidr\_block }}”  
21 vpc\_internet\_gateway: yes  
22 resource\_tags:  
23 Name: “{{ aws\_iac\_fullstackname }}-{{ aws\_nc\_vpc }}”  
24 Environment: “{{ aws\_vpc\_subnet\_envname }}”  
25 “CIDR\_BLOCK”: “{{ aws\_vpc\_cidr\_block }}”

**Request — with\_items:**

35 # create the VPC  
36 - name: VPC | Create the required VPC  
37 ec2\_vpc:  
38 aws\_access\_key: “{{ aws\_access\_key }}”  
39 aws\_secret\_key: “{{ aws\_secret\_key }}”  
40 region: “{{ aws\_region }}”  
41 state: present  
42 cidr\_block: “{{ item.cidr\_block }}”  
43 resource\_tags: “{{ item.resource\_tags }}”  
44 internet\_gateway: “{{ item.vpc\_internet\_gateway }}”  
45 subnets:  
46 “{{ my\_subnets }}”  
47 route\_tables:  
48 “{{ aws\_route\_table\_info }}”  
49 with\_items: aws\_vpc\_info  
50 register: ec2\_vpc\_out

**Response**  **— with\_items** \*\*:\*\*

ok: [localhost] =\> {  
“msg”: {  
“changed”: false,  
“msg”: “All items completed”,  
“results”: [  
{  
“\_ansible\_no\_log”: false,  
“changed”: false,  
“igw\_id”: “igw-dddddddd”,  
“invocation”: {  
“module\_args”: {  
“aws\_access\_key”: “AAAAAAAAAAAAAAAAAAAA”,  
“aws\_secret\_key”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“cidr\_block”: “10.125.0.0/16”,  
“dns\_hostnames”: true,  
“dns\_support”: true,  
“ec2\_url”: null,  
“instance\_tenancy”: “default”,  
“internet\_gateway”: true,  
“profile”: null,  
“region”: “ap-southeast-2”,  
“resource\_tags”: {  
“Environment”: “Test",  
“Name”: “Test-VPC”,  
“CIDR\_BLOCK”: “10.125.0.0/16”

(…)

],  
“vpc”: {  
“cidr\_block”: “10.125.0.0/16”,  
“dhcp\_options\_id”: “dopt-99999999”,  
“id”: “vpc-55555555”,  
“region”: “ap-southeast-2”,  
“state”: “available”  
},  
“vpc\_id”: “vpc-55555555”  
}  
]  
}  
}

After the change to the playbook I had to change the return vpc\_id information from {{ ec2\_vpc\_out.vpc\_id }} to {{ ec2\_vpc\_out.results.0.subnets }}.

As you can see, the output are radically different between each other. Nothing else was changed and I can run both playbooks and despite the output both works as expected.

Does anyone know if this is a bug or if it’s expected ? If it is expected, can someone point me some documentation so I can handle this changes ?

Thank you,  
—Gustavo Aguiar
