# ec2\_vpc\_subnet\_facts getting error accessing vpc\_id from a fact

**URL:** <https://forum.ansible.com/t/ec2-vpc-subnet-facts-getting-error-accessing-vpc-id-from-a-fact/20238>\
**Category:** Ansible Project\
**Created:** [January 16, 2016, 1:53pm UTC](https://forum.ansible.com/t/ec2-vpc-subnet-facts-getting-error-accessing-vpc-id-from-a-fact/20238 "2016-01-16T13:53:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Graham](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@Matthew\_Graham](https://forum.ansible.com/u/Matthew_Graham)\
**Post date:** [January 16, 2016, 1:53pm UTC](https://forum.ansible.com/t/ec2-vpc-subnet-facts-getting-error-accessing-vpc-id-from-a-fact/20238/1 "2016-01-16T13:53:15Z")

</div>

Hi All

I’m very new to Ansible and loving it. Not sure if Im doing this right but having trouble getting the vpc\_id from ec2\_vpc\_subnet\_facts

1. My code runs the module

- name: Get the VPC ID  
ec2\_vpc\_subnet\_facts:  
region: “{{ aws\_region }}”  
filters:  
subnet-id: “{{ aws\_subnet\_id }}”  
register: subnet\_facts

1. Get debug information to make sure what data I have in the variable

- debug: “var=subnet\_facts.subnets”

Output

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“subnet\_facts.subnets”: [  
{  
“availability\_zone”: “ap-southeast-2a”,  
“available\_ip\_address\_count”: 251,  
“cidr\_block”: “10.0.1.0/24”,  
“default\_for\_az”: “false”,  
“id”: “subnet-534f2736”,  
“map\_public\_ip\_on\_launch”: “false”,  
“state”: “available”,  
“tags”: {  
“Name”: “Public A”  
},  
“vpc\_id”: “vpc-776ce112”  
}  
]

1. Set the fact.

- set\_fact: aws\_vpc\_id={{ subnet\_facts.subnets }}

1. Tried to have VPC\_ID set in the ec2\_group

- name: Create Security group for Sinatra Servers  
ec2\_group:  
name: “{{ aws\_security\_group }}”  
description: Security Group for Sinatra Web Servers  
state: present  
vpc\_id: “{ {aws\_vpc\_id.vpc\_id }}”  
rules:
- proto: tcp  
from\_port: 80  
to\_port: 80  
cidr\_ip: 0.0.0.0/0
- proto: tcp  
from\_port: 22  
to\_port: 22  
cidr\_ip: 10.0.0.0/8

1. Get this error

TASK [Create Security group for Sinatra Servers] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost]: FAILED! =\> {“failed”: true, “msg”: “ERROR! ‘unicode object’ has no attribute ‘vpc\_id’”}

Tried a few different things but Im missing something. Im sure its something silly

Regards

M
