-
Notifications
You must be signed in to change notification settings - Fork 2
/
aws-tower-cfme-ansible-create-vpc.yml
104 lines (98 loc) · 3.86 KB
/
aws-tower-cfme-ansible-create-vpc.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
################################################################################################
# Creating an Entire VPC Environment in AWS #
# #
# By Robert J. Calva - Red Hat LATAM - 2022 #
# #
# NOTE: just set the aws_region, aws_zone, vpc_name, cidr_block #
# variables as you wish! #
# #
# IMPORTANT: regarding storage_type information, please take a look at this link: #
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html #
# #
# Variable examples: #
# #
# aws_region could be: sa-east-1 or us-east-1 #
# aws_zone could be: sa-east-1a, sa-east-1b, us-east-1a, us-east-1b #
# #
# Enjoy! #
################################################################################################
- name: Create an Entire VPC Environment in AWS
hosts: localhost
gather_facts: false
connection: local
tasks:
- name: Create the VPC in AWS {{ aws_region }}
ec2_vpc_net:
state: present
name: "{{ vpc_name }}"
tags:
Name: "{{ vpc_name }}"
cidr_block: "{{ cidr_block }}"
region: "{{ aws_region }}"
register: vpc
until: vpc is not failed
retries: 5
- name: Create an AWS Security Group for our Workshop
ec2_group:
name: "aws-workshop-sec-group"
region: "{{ aws_region }}"
description: Workshop Security Group
tags:
Name: "{{ vpc_name }}"
vpc_id: "{{ 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
- proto: tcp
from_port: 9090
to_port: 9090
cidr_ip: 0.0.0.0/0
register: aws_workshop_sec_group
until: aws_workshop_sec_group is not failed
retries: 5
- name: Create Subnet for VPC {{ vpc_name }}
ec2_vpc_subnet:
region: "{{ aws_region }}"
tags:
Name: "{{ vpc_name }}"
vpc_id: "{{ vpc.vpc.id }}"
az: "{{ aws_zone }}"
cidr: "{{ cidr_block }}"
wait_timeout: 600
register: subnet
until: subnet is not failed
retries: 15
- name: VPC Internet Gateway is Present for VPC {{ vpc_name }}
ec2_vpc_igw:
region: "{{ aws_region }}"
tags:
Name: "{{ vpc_name }}"
vpc_id: "{{ vpc.vpc.id }}"
register: igw
until: igw is not failed
retries: 15
- name: VPC Public Subnet Route Table is Present for VPC {{ vpc_name }}
ec2_vpc_route_table:
region: "{{ aws_region }}"
tags:
Name: "{{ vpc_name }}"
vpc_id: "{{ vpc.vpc.id }}"
subnets:
- "{{ subnet.subnet.id }}"
routes:
- dest: 0.0.0.0/0
gateway_id: "{{ igw.gateway_id }}"
register: routetable
until: routetable is not failed
retries: 5
- set_stats:
data:
vpc_id: "{{ vpc.vpc.id }}"
subnet_id: "{{ subnet.subnet.id }}"
per_host: no