-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaws-create-entire-vpc-with-instance.yml
121 lines (116 loc) · 4.85 KB
/
aws-create-entire-vpc-with-instance.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
################################################################################################
# Creating an Entire VPC Environment in AWS #
# #
# By Robert J. Calva - Red Hat LATAM - 2016 #
# #
# NOTE: just set the aws_region, aws_zone, name_zone, attendee, aws_keypair and #
# volume_type 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 #
# name_zone could be: example.com #
# volume_type could be: standard or gp2 #
# #
# Enjoy! #
################################################################################################
- name: Create an Entire VPC Environment in AWS
hosts: localhost
gather_facts: false
connection: local
vars:
- aws_region: us-east-1
- aws_zone: us-east-1a
- name_zone: example.com
- volume_type: standard
- attendee: 'Robert Calva'
- aws_keypair: ansible-workshop-keypair
tasks:
- name: Create the VPC in AWS {{ aws_region }}
ec2_vpc:
state: present
cidr_block: 192.168.0.0/16
resource_tags: { "Name":"Workshop VPC {{ attendee }}" }
subnets:
- cidr: 192.168.1.0/24
az: "{{ aws_zone }}"
resource_tags: { "Name":"workshop-private-subnet" }
internet_gateway: True
route_tables:
- subnets:
- 192.168.1.0/24
routes:
- dest: 0.0.0.0/0
gw: igw
region: "{{ aws_region }}"
wait: yes
register: vpc
- set_fact: vpc_id={{ vpc.vpc_id }}
- set_fact: subnet_id={{ vpc.subnets[0].id }}
- name: Create an AWS Security Group for our Workshop
ec2_group:
name: "aws-workshop-sec-group"
region: "{{ aws_region }}"
description: Locust Security Group
vpc_id: "{{ 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: 443
to_port: 443
cidr_ip: 0.0.0.0/0
register: aws_workshop_sec_group
- name: Create Route53 Workshop Private DNS Zone
route53_zone: zone={{ name_zone }} state=present vpc_region={{ aws_region }} vpc_id={{ vpc_id }} comment='Ansible Workshop DNS Private Zone'
register: rht_forum_private_zone
- name: Create Route53 DNS Record For our AWS Instance into {{name_zone}}
route53:
command: create
zone: "{{ name_zone }}"
private_zone: true
vpc_id: "{{ vpc_id }}"
record: webserver1.{{ name_zone }}
type: A
ttl: 300
value: 192.168.1.10
wait: yes
- name: Creating an AWS Instance for our Webservice
ec2:
key_name: {{ aws_keypair }}
group: aws-workshop-sec-group
instance_type: t2.micro
image: ami-7de77b11
wait: yes
wait_timeout: 500
volumes:
- device_name: /dev/sda1
volume_type: "{{ volume_type }}"
volume_size: 10
delete_on_termination: true
instance_initiated_shutdown_behavior: stop
private_ip: 192.168.1.10
termination_protection: no
instance_tags:
Name: Locust
exact_count: 1
count_tag:
Name: Webserver1
region: "{{ aws_region }}"
vpc_subnet_id: "{{ subnet_id }}"
zone: "{{ aws_zone }}"
assign_public_ip: yes
register: webserver1
- name: Wait for Locust Instance to come up
wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started
with_items: '{{locust.instances}}'