-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_satellite_vm.yml
42 lines (38 loc) · 1.25 KB
/
delete_satellite_vm.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
---
- name: Delete Satellite VM
hosts: localhost
gather_facts: false
vars:
aws_region: "{{ lookup('env', 'AWS_DEFAULT_REGION') }}"
tasks:
- name: Fail if variables not defined
ansible.builtin.assert:
that:
- aws_region is defined
- satellite_vm_name is defined
- satellite_vm_environment is defined
- satellite_vm_type is defined
- purpose is defined
fail_msg: "Required variables not set"
- name: Check if the demo VM is already provisioned
amazon.aws.ec2_instance_info:
filters:
"tag:Name": "{{ satellite_vm_name }}"
"tag:environment": "{{ satellite_vm_environment }}"
"tag:type": "{{ satellite_vm_type }}"
"tag:purpose": "{{ purpose }}"
instance-state-name:
- pending
- running
- shutting-down
- stopping
- stopped
region: "{{ aws_region }}"
register: existing_vm
- name: Delete the VM
amazon.aws.ec2_instance:
instance_ids:
- "{{ existing_vm.instances[0].instance_id }}"
region: "{{ aws_region }}"
state: absent
when: existing_vm.instances is defined and existing_vm.instances | length == 1