-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterminate_web_servers_and_lb.yml
52 lines (46 loc) · 1.32 KB
/
terminate_web_servers_and_lb.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
---
# This playbook terminate AWS instances with tag "ANSIBLE-DEMO"
- hosts: localhost
connection: local
gather_facts: false
vars:
instance_type: 't2.micro'
region: 'us-east-1'
aws_zone: 'b'
instance_tags: '{"Project":"ANSIBLE-DEMO"}'
elb_name: "demo-accounting-web-lb"
web_site_name: 'eric-aws-demo.testlab.space'
tasks:
# Get facts for instances with tag Project equals ANSIBLE
- name: Gather facts
ec2_remote_facts:
region: "{{ region }}"
filters:
"tag:Project": ANSIBLE-DEMO
instance-state-name: running
register: ec2_facts
# Terminate instances found from ec2_remote_facts
- name: Terminate RHEL instance
ec2:
instance_type: "{{ instance_type }}"
instance_tags: "{{ instance_tags }}"
region: "{{ region }}"
wait: true
state: absent
instance_ids: "{{ item.id }}"
with_items: "{{ ec2_facts.instances }}"
# Delete ELB with name "demo-accounting-web-lb"
- name: Delete ELB
ec2_elb_lb:
name: "{{ elb_name }}"
state: absent
region: "{{ region }}"
# Delete DNS entry
- name: Un-register Route53
route53:
command: delete
zone: testlab.space
record: '{{ web_site_name }}'
type: A
wait: yes
overwrite: yes