-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaws-tower-cfme-ansible-delete-entire-vpc-with-instance-new.yml
103 lines (93 loc) · 4.12 KB
/
aws-tower-cfme-ansible-delete-entire-vpc-with-instance-new.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
################################################################################################
# Deleting an Entire VPC Environment in AWS #
# #
# By Robert J. Calva - Red Hat LATAM - 2019 #
# #
# 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: Delete an Entire VPC Environment in AWS
hosts: localhost
gather_facts: false
connection: local
tasks:
- name: Getting EC2 Instance Info {{ instance_name }}
ec2_instance_info:
filters:
"tag:Name": "{{ instance_name }}"
instance-state-name: running
region: "{{ aws_region }}"
register: ec2
- name: Deleting an AWS Instance {{ instance_name }}
ec2:
instance_ids: "{{ ec2.instances[0].instance_id }}"
region: "{{ aws_region }}"
wait: yes
wait_timeout: 500
state: absent
ignore_errors: yes
- name: Gather information about VPC {{ attendee }}
ec2_vpc_net_info:
region: "{{ aws_region }}"
filters:
"tag:Name": "VPC {{ attendee }}"
register: vpc
- name: Gather information about Route Tables for VPC {{ attendee }}
ec2_vpc_route_table_info:
region: "{{ aws_region }}"
filters:
"tag:Name": "VPC {{ attendee }}"
register: rtb
- name: Delete VPC Public Subnet Route Table for VPC {{ attendee }}
ec2_vpc_route_table:
region: "{{ aws_region }}"
route_table_id: "{{ item.id }}"
vpc_id: "{{ vpc.vpcs[0].id }}"
lookup: id
state: absent
loop: "{{ rtb.route_tables }}"
ignore_errors: yes
- name: Delete VPC Internet Gateway for VPC {{ attendee }}
ec2_vpc_igw:
region: "{{ aws_region }}"
vpc_id: "{{ vpc.vpcs[0].id }}"
tags:
Name: "VPC {{ attendee }}"
state: absent
- name: Delete Subnet for VPC {{ attendee }}
ec2_vpc_subnet:
region: "{{ aws_region }}"
vpc_id: "{{ vpc.vpcs[0].id }}"
cidr: "{{ cidr_block }}"
tags:
Name: "VPC {{ attendee }}"
state: absent
- name: Delete an AWS Security Group for our Workshop
ec2_group:
name: "aws-workshop-sec-group"
vpc_id: "{{ vpc.vpcs[0].id }}"
region: "{{ aws_region }}"
tags:
Name: "VPC {{ attendee }}"
state: absent
- name: Deleting the VPC {{ attendee }} in AWS {{ aws_region }}
ec2_vpc_net:
name: "VPC {{ attendee }}"
tags:
Name: "VPC {{ attendee }}"
cidr_block: "{{ cidr_block }}"
purge_cidrs: yes
region: "{{ aws_region }}"
state: absent