-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.yaml
77 lines (77 loc) · 2.64 KB
/
start.yaml
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright 2022 Trevor Lauder.
# SPDX-License-Identifier: MIT
---
- hosts: localhost
vars_files:
- vars/gaming.yaml
- vars/private.yaml
tasks:
- name: Get the spot instance request information
amazon.aws.ec2_spot_instance_info:
region: "{{ region }}"
filters:
state: disabled
tag:Name: "{{ vpc_name }}"
register: spot_instance_request_info
- name: Get the instance information
amazon.aws.ec2_instance_info:
region: "{{ region }}"
instance_ids:
- "{{ spot_instance_request_info.spot_request[0].instance_id }}"
register: spot_instance_info
- name: Get the Gaming Instance volume information
amazon.aws.ec2_snapshot_info:
region: "{{ region }}"
filters:
tag:Name: "{{ vpc_name }}"
tag:device_name: /dev/sda1
register: gaming_instance_snapshot
- name: Get the Games volume information
amazon.aws.ec2_snapshot_info:
region: "{{ region }}"
filters:
tag:Name: "{{ vpc_name }}"
tag:device_name: /dev/xvda
register: games_snapshot
- name: Attach the Gaming Instance volume
amazon.aws.ec2_vol:
region: "{{ region }}"
instance: "{{ spot_instance_request_info.spot_request[0].instance_id }}"
snapshot: "{{ gaming_instance_snapshot.snapshots[0].snapshot_id }}"
delete_on_termination: True
device_name: /dev/sda1
volume_type: gp2
tags:
Name: "{{ vpc_name }}"
- name: Attach the Games volume
amazon.aws.ec2_vol:
region: "{{ region }}"
instance: "{{ spot_instance_request_info.spot_request[0].instance_id }}"
snapshot: "{{ games_snapshot.snapshots[0].snapshot_id }}"
delete_on_termination: False
device_name: /dev/xvda
volume_type: gp2
tags:
Name: "{{ vpc_name }}"
- name: Start the instance
amazon.aws.ec2_instance:
state: started
region: "{{ region }}"
instance_ids:
- "{{ spot_instance_request_info.spot_request[0].instance_id }}"
- name: Delete the first snapshot
amazon.aws.ec2_snapshot:
state: absent
region: "{{ region }}"
wait: true
snapshot_id: "{{ gaming_instance_snapshot.snapshots[0].snapshot_id }}"
- name: Delete the second snapshot
amazon.aws.ec2_snapshot:
state: absent
region: "{{ region }}"
wait: true
snapshot_id: "{{ games_snapshot.snapshots[0].snapshot_id }}"
- name: Print EC2 Public DNS
ansible.builtin.debug:
msg: "{{ spot_instance_info.instances[0].public_dns_name }}"
verbosity: 0