-
Notifications
You must be signed in to change notification settings - Fork 54
/
windows_teardown_ec2.yml
35 lines (32 loc) · 1.37 KB
/
windows_teardown_ec2.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
- hosts: localhost
become: no
tasks:
- name: get ec2 instance information
ec2_instance_facts:
region: "{{ ec2_region }}"
filters:
vpc-id: "{{ ec2_vpc_id }}"
"tag:app": windows_demo
register: ec2_instances
- name: terminate instances
ec2:
region: "{{ ec2_region }}"
state: "absent"
instance_ids: "{{ ec2_instances.instances | map(attribute='instance_id') | list }}"
- name: Get record for router ELB DNS Entry
route53:
command: get
zone: "{{ hosted_zone_domain_name }}"
record: "{{ subdomain | default(ec2_instances.instances[0].tags.role | lower) }}.{{ ec2_name_prefix | lower }}.{{ hosted_zone_domain_name }}"
type: A
register: routerelbrec
when: hosted_zone_domain_name is defined and ec2_name_prefix is defined
- name: Delete Router ELB DNS Entry if it doesn't exist
route53:
#state: present ## Added in Ansible 2.4 will remove need for when statement below
command: delete
zone: "{{ hosted_zone_domain_name }}"
record: "{{ subdomain | default(ec2_instances.instances[0].tags.role | lower) }}.{{ ec2_name_prefix | lower }}.{{ hosted_zone_domain_name }}"
type: A
value: "{{ ec2_instances.instances[0].public_ip_address }}"
when: routerelbrec.set is defined and "{} != routerelbrec.set"