Created
February 5, 2018 11:57
-
-
Save tomwwright/c29d1014a0be0c74b86534d9bee152b1 to your computer and use it in GitHub Desktop.
ansibled : vpc : tasks : setup gateways
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tasks/vpc/setup.gateways.yml | |
# --- | |
# creates the gateways for the VPC, and sets up routing for the subnets | |
# create the internet gateway, saving the output to extract the ID later | |
- name: create internet gateway | |
ec2_vpc_igw: | |
vpc_id: "{{ vpc_id }}" | |
register: create_gateway | |
# create the NAT gateway, looking up the subnet ID by the human readable name: "private-a" | |
- name: create NAT gateway | |
ec2_vpc_nat_gateway: | |
subnet_id: "{{ vpc_subnet_ids['private-a'] }}" | |
region: "{{ aws_region }}" | |
wait: yes | |
if_exist_do_not_create: true | |
register: create_nat_gateway | |
# parse the outputs of the Ansible modules for some important details referred to when setting up routing | |
- name: "set facts: Gateway IDs and IP" | |
set_fact: | |
vpc_gateway_id: "{{ create_gateway.gateway_id }}" | |
vpc_nat_gateway_id: "{{ create_nat_gateway.nat_gateway_id }}" | |
vpc_nat_gateway_ip: "{{ create_nat_gateway.nat_gateway_addresses.public_ip }}" | |
# update the VPCs DNS with the public IP of the new NAT gateway | |
- name: update DNS with NAT gateway IP | |
route53: | |
zone: "{{ vpc_dns_zone }}" | |
private_zone: yes | |
record: nat.{{ vpc_dns_zone }} | |
type: A | |
value: "{{ vpc_nat_gateway_ip }}" | |
# private route table that routes through the NAT -- attach it to our three private subnets | |
- name: create route table for private subnets | |
ec2_vpc_route_table: | |
vpc_id: "{{ vpc_id }}" | |
tags: | |
Name: "{{ vpc_name }}-private" | |
subnets: | |
- "{{ vpc_subnet_ids['private-a'] }}" | |
- "{{ vpc_subnet_ids['private-b'] }}" | |
- "{{ vpc_subnet_ids['private-c'] }}" | |
routes: | |
- dest: 0.0.0.0/0 | |
gateway_id: "{{ vpc_nat_gateway_id }}" | |
# public route table that routes through the internet gateway -- attach it to our three public subnets | |
- name: create route table for public subnets | |
ec2_vpc_route_table: | |
vpc_id: "{{ vpc_id }}" | |
tags: | |
Name: "{{ vpc_name }}-public" | |
subnets: | |
- "{{ vpc_subnet_ids['public-a'] }}" | |
- "{{ vpc_subnet_ids['public-b'] }}" | |
- "{{ vpc_subnet_ids['public-c'] }}" | |
routes: | |
- dest: 0.0.0.0/0 | |
gateway_id: "{{ vpc_gateway_id }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 29: My linter complains: Missing property "state". Should add property
state: present
?