-
Notifications
You must be signed in to change notification settings - Fork 0
/
teardown.yml
52 lines (52 loc) · 1.82 KB
/
teardown.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
---
- hosts: localhost
connection: local
gather_facts: False
vars_files:
- vars/aws.yml
- vars/aws_secrets.yml
tasks:
- name: get admin's public ip address
ipify_facts:
- name: generate cloudformation template.
shell: python scripts/make_cf_template.py > files/cf_template.json
- name: Ensure cloudformation is up
cloudformation:
aws_access_key: "{{ cloudformation_access_key }}"
aws_secret_key: "{{ cloudformation_secret_key }}"
stack_name: "{{ stack_name }}"
state: present
region: "{{ aws_region }}"
template: files/cf_template.json
template_parameters:
KeyName: "{{ key_name }}"
Name: "{{ stack_name }}"
SSHLocation: "{{ ipify_public_ip }}/32"
register: cloudformation
- name: "Remove {{ stack_name }} stack"
route53:
aws_access_key: "{{ route53_access_key }}"
aws_secret_key: "{{ route53_secret_key }}"
command: delete
overwrite: true
zone: "{{ zone }}"
record: "{{ stack_name }}.{{ zone }}"
type: A
value: "{{ cloudformation.stack_outputs.InstanceIPAddress }}"
- name: Remove wildcard subdomains for stack
route53:
aws_access_key: "{{ route53_access_key }}"
aws_secret_key: "{{ route53_secret_key }}"
command: delete
overwrite: true
zone: "{{ zone }}"
record: "*.{{ stack_name }}.{{ zone }}"
type: A
value: "{{ cloudformation.stack_outputs.InstanceIPAddress }}"
- name: Destroy cloudformation to create ec2, security group, and EIP.
cloudformation:
aws_access_key: "{{ cloudformation_access_key }}"
aws_secret_key: "{{ cloudformation_secret_key }}"
stack_name: "{{ stack_name }}"
state: absent
region: "{{ aws_region }}"