# ec2\_vpc default gw not working?

**URL:** <https://forum.ansible.com/t/ec2-vpc-default-gw-not-working/17613>\
**Category:** Ansible Project\
**Created:** [February 24, 2015, 8:36pm UTC](https://forum.ansible.com/t/ec2-vpc-default-gw-not-working/17613 "2015-02-24T20:36:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pablo\_Escobar](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Pablo\_Escobar](https://forum.ansible.com/u/Pablo_Escobar)\
**Post date:** [February 24, 2015, 8:36pm UTC](https://forum.ansible.com/t/ec2-vpc-default-gw-not-working/17613/1 "2015-02-24T20:36:32Z")

</div>

Hi,

I have been doing some tests to deploy a ec2 vpc with ansible but I cannot manage to configure the default gw so the machines inside the vpc have no internet access.

After doing some debugging in my playbook I just copied&paste the example from the documentation in [http://docs.ansible.com/ec2\_vpc\_module.html](http://docs.ansible.com/ec2_vpc_module.html) to see if it works but still I don’t get the default gw in the vpc

This is the example I tried from documentation which is not working for me. (just changing availability zone and region) I am using ansible 1.8.2 in ubuntu14.04 with python 2.7.6

any clue about how to fix this?

```auto
# Full creation example with subnets and optional availability zones.
# The absence or presence of subnets deletes or creates them respectively.
      ec2_vpc:
        state: present
        cidr_block: [172.22.0.0/16](http://172.22.0.0/16)
        resource_tags: { "Environment":"Development" }
        subnets:
          - cidr: [172.22.1.0/24](http://172.22.1.0/24)
            az: us-west-2c
            resource_tags: { "Environment":"Dev", "Tier" : "Web" }
          - cidr: [172.22.2.0/24](http://172.22.2.0/24)
            az: us-west-2b
            resource_tags: { "Environment":"Dev", "Tier" : "App" }
          - cidr: [172.22.3.0/24](http://172.22.3.0/24)
            az: us-west-2a
            resource_tags: { "Environment":"Dev", "Tier" : "DB" }
        internet_gateway: True
        route_tables:
          - subnets:
              - [172.22.2.0/24](http://172.22.2.0/24)
              - [172.22.3.0/24](http://172.22.3.0/24)
            routes:
              - dest: [0.0.0.0/0](http://0.0.0.0/0)
                gw: igw
          - subnets:
              - [172.22.1.0/24](http://172.22.1.0/24)
            routes:
              - dest: [0.0.0.0/0](http://0.0.0.0/0)
                gw: igw
        region: us-west-2
      register: vpc

```

thanks in advance,

Pablo

---

<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:** [February 26, 2015, 9:41am UTC](https://forum.ansible.com/t/ec2-vpc-default-gw-not-working/17613/2 "2015-02-26T09:41:52Z")

</div>

So you’re saying that after running that the IGW is not associated with your subnet(s)?  
Also, can you confirm that the routing tables have the correct subnets associations?

---

<div class="post-metadata">

**Author:** ![Pablo\_Escobar](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Pablo\_Escobar](https://forum.ansible.com/u/Pablo_Escobar)\
**Post date:** [February 28, 2015, 11:51am UTC](https://forum.ansible.com/t/ec2-vpc-default-gw-not-working/17613/3 "2015-02-28T11:51:34Z")

</div>

> So you're saying that after running that the IGW is not associated with  
> your subnet(s)?

yes. I have to manually add the IGW to the vpc in the console so the  
machines have internet access

> Also, can you confirm that the routing tables have the correct subnets  
> associations?

in the routes section I only get this;

Destination Target Status Propagated  
172.1.0.0/16 local Active No

In the "subnets associations" section I get this:

Subnet CIDR  
You do not have any subnet associations.  
The following subnets have not been associated with any route tables and  
are therefore using the main table routes:

Subnet CIDR  
All your subnets are associated with a route table.

---

<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:** [February 28, 2015, 5:11pm UTC](https://forum.ansible.com/t/ec2-vpc-default-gw-not-working/17613/4 "2015-02-28T17:11:32Z")

</div>

Just had a look at all my tasks involving ec2\_vpc module and all of them have

`internet_gateway: yes`  
I believe that is your problem. In that case, the documentation example should reflect this, as per the shown parameter values in the table.  
I took a look at ec2\_vpc.py and there isn’t anything suggesting that True/False values wouldn’t work, hence you get no error.

Hope this helps,

Dan.

---

<div class="post-metadata">

**Author:** ![Pablo\_Escobar](https://avatars.discourse-cdn.com/v4/letter/p/8797f3/32.png) [@Pablo\_Escobar](https://forum.ansible.com/u/Pablo_Escobar)\
**Post date:** [March 4, 2015, 9:34pm UTC](https://forum.ansible.com/t/ec2-vpc-default-gw-not-working/17613/5 "2015-03-04T21:34:44Z")

</div>

Hi Dan,

thanks for your help, but I run this playbook and still no IGW

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 5, 2015, 5:30am UTC](https://forum.ansible.com/t/ec2-vpc-default-gw-not-working/17613/6 "2015-03-05T05:30:46Z")

</div>

Hi Pablo,

This is my working ansible task to create vpc:

- name: VPC | Creating and AWS VPC inside mentioned Region  
local\_action:  
module: ec2\_vpc  
region: “{{ vpc\_region }}”  
state: present  
cidr\_block: “{{ cidr\_block }}”  
resource\_tags: { “Name”:“{{ vpc\_name| default(test) }}\_vpc” }  
subnets:
- cidr: “{{ public\_cidr }}”  
az: “{{ public\_az }}”  
resource\_tags: { “Name”:“{{ vpc\_name| default(test) }}\_public\_subnet” }
- cidr: “{{ private\_cidr }}”  
az: “{{ private\_az }}”  
resource\_tags: { “Name”:“{{ vpc\_name| default(test) }}\_private\_subnet” }  
internet\_gateway: True  
route\_tables:
- subnets:
- “{{ public\_cidr }}”  
routes:
- dest: 0.0.0.0/0  
gw: igw  
register: vpc

here is my var/main.yml
