Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't figure out why subnet is being updated

I am creating a VPC in AWS using Ansible. The following play is run

- name: create vpc with multi-az subnets
  ec2_vpc:
    region: "{{ region }}"
    cidr_block: "{{ vpc_cidr_block }}"
    resource_tags: '{"Name":"{{ prefix }}_vpc"}'
    subnets:
      - cidr: "{{ vpc_cidr_subnet_public_0 }}"
        az: "{{ region }}{{ availability_zone_0 }}"
        resource_tags: '{"Name":"{{ prefix }}_subnet_public_0", "Class":"web", "Partner":prefix }'
      - cidr: "{{ vpc_cidr_subnet_private_0 }}"
        az: "{{ region }}{{ availability_zone_0 }}"
        resource_tags: '{"Name":"{{ prefix }}_subnet_private_0", "Class":"db", "Partner":prefix }'
      - cidr: "{{ vpc_cidr_subnet_private_1 }}"
        az: "{{ region }}{{ availability_zone_1 }}"
        resource_tags: '{"Name":"{{ prefix }}_subnet_private_1", "Class":"db", "Partner":prefix }'
    internet_gateway: yes
    route_tables:
      - subnets:
        - "{{ vpc_cidr_subnet_public_0 }}"
        routes:
          - dest: 0.0.0.0/0
            gw: igw
    wait: yes
  register: vpc

First time around this creates everything perfectly. Second time around, I expect it to not do anything as everything has been created, however, the public subnet is updated to a private one.

Why? What am I doing wrong?

[UPDATE]

Here are the variables:

---
region: eu-west-1
prefix: staging
vpc_environment: staging
vpc_cidr_block: 20.0.0.0/16
vpc_cidr_subnet_public_0: 20.0.0.0/24
vpc_cidr_subnet_private_0: 20.0.1.0/24
vpc_cidr_subnet_private_1: 20.0.2.0/24
availability_zone_0: b
availability_zone_1: c

Also just to clarify on what change is happening. All the resource tags of the one subnet (public) are being overwritten with the tags of another subnet (private).

like image 830
Ryan-Neal Mes Avatar asked Feb 01 '16 07:02

Ryan-Neal Mes


People also ask

What happens if subnet is wrong?

Incorrect Subnet Mask: If a network uses a subnet mask other than the default mask for its address class, and a client is still configured with the default subnet mask for the address class, communication will fail to some nearby networks but not to distant ones.

How is a subnet identified?

The Subnet address is identified by all 0 bits in the Host part of the address. The first host within the subnet is identified by all 0s and a 1. The last host is identified by all 1s and a 0. The broadcast address is the all 1s.

Why would you change subnet mask?

Why do we change a Subnet Mask? It is a recommended procedure for increasing a DHCP scope when the current scope has entirely consumed the current subnet mask. However, this method requires you to change all subnet hosts and gateways.


1 Answers

This was caused by a bug in ansible-modules-core in master - ec2_vpc. I have logged a bug and created a PR to resolve the issue. See PR for details and the actual break. Hopefully it gets merged soon!

[UPDATE] Merged

like image 65
Ryan-Neal Mes Avatar answered Oct 07 '22 23:10

Ryan-Neal Mes