| 1 |
--- |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
- name: Create a disk |
| 17 |
google.cloud.gcp_compute_disk: |
| 18 |
name: disk-snapshot |
| 19 |
zone: us-central1-a |
| 20 |
project: "{{ gcp_project }}" |
| 21 |
auth_kind: "{{ gcp_cred_kind }}" |
| 22 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 23 |
state: present |
| 24 |
register: disk |
| 25 |
- name: Delete a snapshot |
| 26 |
google.cloud.gcp_compute_snapshot: |
| 27 |
name: "{{ resource_name }}" |
| 28 |
source_disk: "{{ disk }}" |
| 29 |
zone: us-central1-a |
| 30 |
labels: |
| 31 |
my_label: value |
| 32 |
project: "{{ gcp_project }}" |
| 33 |
auth_kind: "{{ gcp_cred_kind }}" |
| 34 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 35 |
state: absent |
| 36 |
|
| 37 |
- name: Create a snapshot |
| 38 |
google.cloud.gcp_compute_snapshot: |
| 39 |
name: "{{ resource_name }}" |
| 40 |
source_disk: "{{ disk }}" |
| 41 |
zone: us-central1-a |
| 42 |
labels: |
| 43 |
my_label: value |
| 44 |
project: "{{ gcp_project }}" |
| 45 |
auth_kind: "{{ gcp_cred_kind }}" |
| 46 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 47 |
state: present |
| 48 |
register: result |
| 49 |
- name: Assert changed is true |
| 50 |
ansible.builtin.assert: |
| 51 |
that: |
| 52 |
- result.changed == true |
| 53 |
- name: Verify that snapshot was created |
| 54 |
google.cloud.gcp_compute_snapshot_info: |
| 55 |
filters: |
| 56 |
- name = {{ resource_name }} |
| 57 |
project: "{{ gcp_project }}" |
| 58 |
auth_kind: "{{ gcp_cred_kind }}" |
| 59 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 60 |
scopes: |
| 61 |
- https://www.googleapis.com/auth/compute |
| 62 |
register: results |
| 63 |
- name: Verify that command succeeded |
| 64 |
ansible.builtin.assert: |
| 65 |
that: |
| 66 |
- results['resources'] | length == 1 |
| 67 |
|
| 68 |
- name: Create a snapshot that already exists |
| 69 |
google.cloud.gcp_compute_snapshot: |
| 70 |
name: "{{ resource_name }}" |
| 71 |
source_disk: "{{ disk }}" |
| 72 |
zone: us-central1-a |
| 73 |
labels: |
| 74 |
my_label: value |
| 75 |
project: "{{ gcp_project }}" |
| 76 |
auth_kind: "{{ gcp_cred_kind }}" |
| 77 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 78 |
state: present |
| 79 |
register: result |
| 80 |
- name: Assert changed is false |
| 81 |
ansible.builtin.assert: |
| 82 |
that: |
| 83 |
- result.changed == false |
| 84 |
|
| 85 |
- name: Delete a snapshot |
| 86 |
google.cloud.gcp_compute_snapshot: |
| 87 |
name: "{{ resource_name }}" |
| 88 |
source_disk: "{{ disk }}" |
| 89 |
zone: us-central1-a |
| 90 |
labels: |
| 91 |
my_label: value |
| 92 |
project: "{{ gcp_project }}" |
| 93 |
auth_kind: "{{ gcp_cred_kind }}" |
| 94 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 95 |
state: absent |
| 96 |
register: result |
| 97 |
- name: Assert changed is true |
| 98 |
ansible.builtin.assert: |
| 99 |
that: |
| 100 |
- result.changed == true |
| 101 |
- name: Verify that snapshot was deleted |
| 102 |
google.cloud.gcp_compute_snapshot_info: |
| 103 |
filters: |
| 104 |
- name = {{ resource_name }} |
| 105 |
project: "{{ gcp_project }}" |
| 106 |
auth_kind: "{{ gcp_cred_kind }}" |
| 107 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 108 |
scopes: |
| 109 |
- https://www.googleapis.com/auth/compute |
| 110 |
register: results |
| 111 |
- name: Verify that command succeeded |
| 112 |
ansible.builtin.assert: |
| 113 |
that: |
| 114 |
- results['resources'] | length == 0 |
| 115 |
|
| 116 |
- name: Delete a snapshot that does not exist |
| 117 |
google.cloud.gcp_compute_snapshot: |
| 118 |
name: "{{ resource_name }}" |
| 119 |
source_disk: "{{ disk }}" |
| 120 |
zone: us-central1-a |
| 121 |
labels: |
| 122 |
my_label: value |
| 123 |
project: "{{ gcp_project }}" |
| 124 |
auth_kind: "{{ gcp_cred_kind }}" |
| 125 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 126 |
state: absent |
| 127 |
register: result |
| 128 |
- name: Assert changed is false |
| 129 |
ansible.builtin.assert: |
| 130 |
that: |
| 131 |
- result.changed == false |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
- name: Delete a disk |
| 136 |
google.cloud.gcp_compute_disk: |
| 137 |
name: disk-snapshot |
| 138 |
zone: us-central1-a |
| 139 |
project: "{{ gcp_project }}" |
| 140 |
auth_kind: "{{ gcp_cred_kind }}" |
| 141 |
service_account_file: "{{ gcp_cred_file | default(omit) }}" |
| 142 |
state: absent |
| 143 |
register: disk |
| 144 |
ignore_errors: true |