# ec2\_vpc\_route\_table playbook error was: 'dict object' has no attribute subnet

**URL:** <https://forum.ansible.com/t/ec2-vpc-route-table-playbook-error-was-dict-object-has-no-attribute-subnet/29489>\
**Category:** Ansible Project\
**Tags:** kubernetes\
**Created:** [January 22, 2019, 11:51am UTC](https://forum.ansible.com/t/ec2-vpc-route-table-playbook-error-was-dict-object-has-no-attribute-subnet/29489 "2019-01-22T11:51:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Button](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@Steve\_Button](https://forum.ansible.com/u/Steve_Button)\
**Post date:** [January 22, 2019, 11:51am UTC](https://forum.ansible.com/t/ec2-vpc-route-table-playbook-error-was-dict-object-has-no-attribute-subnet/29489/1 "2019-01-22T11:51:09Z")

</div>

I have a previously working piece of Ansible that I’ve inherited for a previous contractor, and I’m getting an error message that doesn’t lead me in the right direction. I have tried searching for a few days now, with no joy, and my colleagues can’t figure it out either.

The Ansible in question is :-

```auto
- name: Routes | Set up NAT-protected route table
  ec2_vpc_route_table:
    vpc_id: "{{ ec2_vpc_net_reg.vpc.id }}"
    region: "{{ vpc_region }}"
    tags:
      Name: "Internal {{ item.subnet_id }}"
    subnets:
      - "{{ az_to_private_sub[public_subnets_to_az[item.subnet_id]] }}"
      - "{{ az_to_private_data_sub[public_subnets_to_az[item.subnet_id]] }}"
    routes:
      - dest: 0.0.0.0/0
        gateway_id: "{{ item.nat_gateway_id }}"
  loop: "{{ existing_nat_gateways.result|flatten(levels=1) }}"
  #with_items: "{{ existing_nat_gateways.result }}"
  register: nat_route_table
  retry: 2
  delay: 10

```

And the error message is :-

```auto
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute u'subnet-0facefaceface9'\n\n

```

```auto
The error appears to have been in '/cup/core-kubernetes-linux/ansible/roles/aws_vpc/tasks/routes.yml': line 62, column 3, but may\n

```

```auto
be elsewhere in the file depending on the exact syntax problem.\n\n

```

```auto
The offending line appears to be:\n\n\n

```

```auto
- name: Routes | Set up NAT-protected route table\n

```

```auto
  ^ here\n

```

```auto
"}

```

I have added some carriage returns to make it a bit more readable.

I have tried adding extra debug, for az\_to\_private\_sub and public\_subnet\_to\_az, and these look OK. I’ve tried reading the [docs](https://docs.ansible.com/ansible/2.5/user_guide/playbooks_loops.html#using-register-with-a-loop)

Can anyone suggest where I should look next?

Thanks!

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [January 22, 2019, 12:05pm UTC](https://forum.ansible.com/t/ec2-vpc-route-table-playbook-error-was-dict-object-has-no-attribute-subnet/29489/2 "2019-01-22T12:05:35Z")

</div>

Use debug statements so that you know what is in “existing\_nat\_gateways.result” and “public\_subnets\_to\_az”.

It looks to me as if there is no element called “subnet-0facefaceface9” in the dictionary “public\_subnets\_to\_az” (that is a very cool subnet ID by the way).

Regards, K.

---

<div class="post-metadata">

**Author:** ![Steve\_Button](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@Steve\_Button](https://forum.ansible.com/u/Steve_Button)\
**Post date:** [January 22, 2019, 12:49pm UTC](https://forum.ansible.com/t/ec2-vpc-route-table-playbook-error-was-dict-object-has-no-attribute-subnet/29489/3 "2019-01-22T12:49:28Z")

</div>

Yes, the actual subnet id was subnet-0f18a0d4a7e9c7719. I was concerned that putting the subnet ID and other IDs into here might (somehow?) be a security issue. I’ve deleted the whole VPC now, so it won’t be a problem.

Here’s the additional debug (which all looks fine to my eyes!!)

TASK [aws\_vpc : Routes | Debug public\_subnets\_to\_az] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /cup/core-kubernetes-linux/ansible/roles/aws\_vpc/tasks/routes.yml:59  
ok: [localhost] =\> {  
“public\_subnets\_to\_az”: {  
“subnet-0d6f53bad96008956”: “eu-west-1c”  
}  
}

TASK [aws\_vpc : Routes | Debug existing\_nat\_gateways.result] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /cup/core-kubernetes-linux/ansible/roles/aws\_vpc/tasks/routes.yml:74  
ok: [localhost] =\> {  
“existing\_nat\_gateways.result”: [  
{  
“create\_time”: “2019-01-21T15:08:50+00:00”,  
“nat\_gateway\_addresses”: [  
{  
“allocation\_id”: “eipalloc-0b86cd580c67ad534”,  
“network\_interface\_id”: “eni-0907d51d9f17e3ff4”,  
“private\_ip”: “172.17.3.106”,  
“public\_ip”: “34.246.20.83”  
}  
],  
“nat\_gateway\_id”: “nat-01e48244fa76ff742”,  
“state”: “available”,  
“subnet\_id”: “subnet-0d6f53bad96008956”,  
“tags”: {},  
“vpc\_id”: “vpc-07fd6abc9b3c96674”  
},  
{  
“create\_time”: “2019-01-21T15:08:47+00:00”,  
“nat\_gateway\_addresses”: [  
{  
“allocation\_id”: “eipalloc-0dd6969c7deb9b616”,  
“network\_interface\_id”: “eni-00a24e6de1b45cdee”,  
“private\_ip”: “172.17.1.252”,  
“public\_ip”: “63.34.105.22”  
}  
],  
“nat\_gateway\_id”: “nat-0fd2bad6baffad428”,  
“state”: “available”,  
“subnet\_id”: “subnet-0f18a0d4a7e9c7719”,  
“tags”: {},  
“vpc\_id”: “vpc-07fd6abc9b3c96674”  
},  
{  
“create\_time”: “2019-01-21T15:08:49+00:00”,  
“nat\_gateway\_addresses”: [  
{  
“allocation\_id”: “eipalloc-018a80fb6bd4a2efc”,  
“network\_interface\_id”: “eni-0e8507f1ba250dfb9”,  
“private\_ip”: “172.17.2.18”,  
“public\_ip”: “63.34.176.76”  
}  
],  
“nat\_gateway\_id”: “nat-0fb938e1aa8784738”,  
“state”: “available”,  
“subnet\_id”: “subnet-079e51dbe6bcaf502”,  
“tags”: {},  
“vpc\_id”: “vpc-07fd6abc9b3c96674”  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![Steve\_Button](https://avatars.discourse-cdn.com/v4/letter/s/b5a626/32.png) [@Steve\_Button](https://forum.ansible.com/u/Steve_Button)\
**Post date:** [January 22, 2019, 4:17pm UTC](https://forum.ansible.com/t/ec2-vpc-route-table-playbook-error-was-dict-object-has-no-attribute-subnet/29489/4 "2019-01-22T16:17:26Z")

</div>

I _have_ noticed that when I destroy the VPC and re-run the job the existing nat gateways debug shows as “pending”, even when I show the debug, put in a 20 minute delay and then show the debug again. This seems really odd to me. I even went on to the AWS console and the However, when I re-run the job it shows as “available” and it complains about one of the eu-west-1x-public-subnet (with x being a, b or c). The route table DOES seem to have those three subnets in, but when the job fails, they disappear.
