-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsnapshot-test.yml
70 lines (62 loc) · 1.99 KB
/
snapshot-test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
- hosts: gcp
gather_facts: yes
vars:
zone: us-central1-a
instance_name: instance-1
project_id: tidal-surf-250712
service_account_file: /Users/dan/Downloads/tidal-surf-250712-e8ebb3f4cdb3.json
timestamp: "{{ ansible_date_time.epoch }}"
tasks:
- name: return gcp instance facts
gcp_compute_instance_info:
zone: "{{ zone }}"
filters:
- name = "{{ instance_name }}"
project: "{{ project_id }}"
auth_kind: serviceaccount
service_account_file: "{{ service_account_file }}"
delegate_to: localhost
register: gcp_facts
- name: output gcp instance facts
debug:
var: gcp_facts
- name: output gcp disk 0 device name
debug:
var: gcp_facts['resources'][0]['disks'][0]['deviceName']
- name: create a snapshot
gcp_compute_snapshot:
name: "{{ instance_name }}-{{ timestamp }}"
source_disk:
name: "{{ gcp_facts['resources'][0]['disks'][0]['deviceName'] }}"
zone: "{{ zone }}"
labels:
my_label: label-mclabelface
project: "{{ project_id }}"
auth_kind: serviceaccount
service_account_file: /Users/dan/Downloads/tidal-surf-250712-e8ebb3f4cdb3.json
state: present
register: create_task
delegate_to: localhost
failed_when: create_task.changed == false
- name: outcome of create snapshot task
debug:
var: create_task
- pause:
prompt: "Pausing to check snapshot creation..."
- name: remove a snapshot
gcp_compute_snapshot:
name: "{{ instance_name }}-{{ timestamp }}"
source_disk:
name: "{{ gcp_facts['resources'][0]['disks'][0]['deviceName'] }}"
zone: "{{ zone }}"
project: "{{ project_id }}"
auth_kind: serviceaccount
service_account_file: /Users/dan/Downloads/tidal-surf-250712-e8ebb3f4cdb3.json
state: absent
register: destroy_task
delegate_to: localhost
failed_when: destroy_task.changed == false
- name: outcome of destroy snapshot task
debug:
var: destroy_task