-
Notifications
You must be signed in to change notification settings - Fork 20
/
adhoc-deprovision-ec2-ci.yml
50 lines (47 loc) · 1.5 KB
/
adhoc-deprovision-ec2-ci.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
# This playbook will need some variables to terminate instances, passed as variables
# needed variables:
# aws_ec2_region: us-east-2
# aws_access_key:
# aws_secret_key:
# aws_ec2_instance_ids:
# - i-longinstanceid
# - i-otherlonginstid
#
---
- hosts: localhost
gather_facts: False
become: False
tasks:
- name: Delete EC2 instance[s]
amazon.aws.ec2_instance:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
region: "{{ aws_ec2_region }}"
instance_ids: >-
{{ duffy_in.nodes | json_query(nodes_id_query) }}
state: absent
wait: False
register: ec2_delete_result
vars:
nodes_id_query: "[*].data.provision.ec2_instance_id"
- name: Deleting route53 record[s]
community.aws.route53:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
hosted_zone_id: "{{ aws_route53_zoneid }}"
overwrite: True
record: "{{ item.hostname }}"
state: absent
type: A
wait: no
with_items: "{{ duffy_in.nodes | json_query(nodes_name_query ) }}"
vars:
nodes_name_query: "[*].data.provision"
loop_control:
label: "{{ item.hostname }}"
- name: Sending data back to Duffy
set_fact:
duffy_out:
nodes: "{{ duffy_in.nodes | json_query(ec2_delete_result_query) }}"
vars:
ec2_delete_result_query: "[*].data.provision"