-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterminate_eventpost_instances.yml
30 lines (29 loc) · 1.14 KB
/
terminate_eventpost_instances.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
# Tasks block for terminating eventpost instances in AWS
# Instances are created with a certain tag so they can then be retireved and managed.
- name: Terminate EvenPost instances
block:
# Task for getting the desired instances by using their tags,
- name: Get AWS EvenPost instances
ec2_instance_info:
# Tags
filters:
"tag:Name": ["events", "notifications"]
# Specify credential
aws_access_key: "{{aws_access_key_id}}"
aws_secret_key: "{{aws_secret_access_key}}"
security_token: "{{aws_session_token}}"
# Register instances info
register: old_ec2
# Task for terminating instances based on their previously adquired IDs.
- name: Terminate AWS EventPost instances
ec2:
# Specify 'absent' state (it terminates the instances)
state: absent
# Specify instances to terminate
instance_ids: "{{item.instance_id}}"
region: us-east-1
aws_access_key: "{{aws_access_key_id}}"
aws_secret_key: "{{aws_secret_access_key}}"
security_token: "{{aws_session_token}}"
with_items:
- "{{ old_ec2.instances }}"