-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2-tear.yml
33 lines (28 loc) · 937 Bytes
/
ec2-tear.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
# This play book can only terminate AWC EC2 instance
# Created by Arun Ghanta on 26/27th April for Arctiq Ansible Assignment
# The vars file has to be placed outside the directory in which this playbook resides
# Created using the knowledge I have and as well as online resources
---
- hosts: control
connection: local
gather_facts: False
vars_files:
- ../vars.yml
tasks:
- name: Provision Instance/VM
ec2_remote_facts:
aws_access_key: "{{ access_key }}"
aws_secret_key: "{{ secret_key }}"
region: "{{ aws_region }}"
filters:
instance-state-name: running
register: ec2
- debug: var=ec2.instances[0].id
- name: Teardown Instance
ec2:
aws_access_key: "{{ access_key }}"
aws_secret_key: "{{ secret_key }}"
state: absent
instance_ids: "{{ ec2.instances[0].id }}"
region: "{{ aws_region }}"
wait: True