ec2_vpc_subnet_facts getting error accessing vpc_id from a fact

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