2019-10-21 14:55:44 +02:00
|
|
|
- name: fetch AZ availability
|
|
|
|
aws_az_info:
|
|
|
|
register: az_info
|
|
|
|
- name: Assert that we have multiple AZs available to us
|
|
|
|
assert:
|
|
|
|
that: az_info.availability_zones | length >= 2
|
|
|
|
|
|
|
|
- name: pick AZs
|
2019-05-10 20:43:15 +02:00
|
|
|
set_fact:
|
2019-10-21 14:55:44 +02:00
|
|
|
subnet_a_az: '{{ az_info.availability_zones[0].zone_name }}'
|
|
|
|
subnet_b_az: '{{ az_info.availability_zones[1].zone_name }}'
|
2019-05-10 20:43:15 +02:00
|
|
|
|
|
|
|
- name: Create VPC for use in testing
|
|
|
|
ec2_vpc_net:
|
2019-10-21 14:55:44 +02:00
|
|
|
name: "{{ vpc_name }}"
|
|
|
|
cidr_block: "{{ vpc_cidr }}"
|
2019-05-10 20:43:15 +02:00
|
|
|
tags:
|
|
|
|
Name: Ansible ec2_instance Testing VPC
|
|
|
|
tenancy: default
|
|
|
|
register: testing_vpc
|
|
|
|
|
|
|
|
- name: Create internet gateway for use in testing
|
|
|
|
ec2_vpc_igw:
|
|
|
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
|
|
state: present
|
|
|
|
register: igw
|
|
|
|
|
|
|
|
- name: Create default subnet in zone A
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
state: present
|
|
|
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
2019-10-21 14:55:44 +02:00
|
|
|
cidr: "{{ subnet_a_cidr }}"
|
|
|
|
az: "{{ subnet_a_az }}"
|
2019-05-10 20:43:15 +02:00
|
|
|
resource_tags:
|
|
|
|
Name: "{{ resource_prefix }}-subnet-a"
|
|
|
|
register: testing_subnet_a
|
|
|
|
|
|
|
|
- name: Create secondary subnet in zone B
|
|
|
|
ec2_vpc_subnet:
|
|
|
|
state: present
|
|
|
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
2019-10-21 14:55:44 +02:00
|
|
|
cidr: "{{ subnet_b_cidr }}"
|
|
|
|
az: "{{ subnet_b_az }}"
|
2019-05-10 20:43:15 +02:00
|
|
|
resource_tags:
|
|
|
|
Name: "{{ resource_prefix }}-subnet-b"
|
|
|
|
register: testing_subnet_b
|
|
|
|
|
|
|
|
- name: create routing rules
|
|
|
|
ec2_vpc_route_table:
|
|
|
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
|
|
tags:
|
|
|
|
created: "{{ resource_prefix }}-route"
|
|
|
|
routes:
|
|
|
|
- dest: 0.0.0.0/0
|
|
|
|
gateway_id: "{{ igw.gateway_id }}"
|
|
|
|
subnets:
|
|
|
|
- "{{ testing_subnet_a.subnet.id }}"
|
|
|
|
- "{{ testing_subnet_b.subnet.id }}"
|
|
|
|
|
|
|
|
- name: create a security group with the vpc
|
|
|
|
ec2_group:
|
|
|
|
name: "{{ resource_prefix }}-sg"
|
|
|
|
description: a security group for ansible tests
|
|
|
|
vpc_id: "{{ testing_vpc.vpc.id }}"
|
|
|
|
rules:
|
|
|
|
- proto: tcp
|
|
|
|
from_port: 22
|
|
|
|
to_port: 22
|
|
|
|
cidr_ip: 0.0.0.0/0
|
|
|
|
- proto: tcp
|
|
|
|
from_port: 80
|
|
|
|
to_port: 80
|
|
|
|
cidr_ip: 0.0.0.0/0
|
|
|
|
register: sg
|