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).
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.
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 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With