| 1 |
- import_role: |
| 2 |
name: prepare_vmware_tests |
| 3 |
vars: |
| 4 |
setup_attach_host: true |
| 5 |
setup_datastore: true |
| 6 |
setup_virtualmachines: true |
| 7 |
|
| 8 |
# Test0001: Try to delete the non-existent snapshot |
| 9 |
- name: 0001 - Delete non-existent snapshot |
| 10 |
community.vmware.vmware_guest_snapshot: |
| 11 |
validate_certs: false |
| 12 |
hostname: '{{ vcenter_hostname }}' |
| 13 |
username: '{{ vcenter_username }}' |
| 14 |
password: '{{ vcenter_password }}' |
| 15 |
datacenter: "{{ dc1 }}" |
| 16 |
name: "{{ virtual_machines[0].name }}" |
| 17 |
folder: "{{ virtual_machines[0].folder }}" |
| 18 |
state: absent |
| 19 |
snapshot_name: snap_a |
| 20 |
|
| 21 |
# Test0002: Create two snapshots |
| 22 |
- name: 0002 - Create snapshot |
| 23 |
community.vmware.vmware_guest_snapshot: |
| 24 |
validate_certs: false |
| 25 |
hostname: '{{ vcenter_hostname }}' |
| 26 |
username: '{{ vcenter_username }}' |
| 27 |
password: '{{ vcenter_password }}' |
| 28 |
datacenter: "{{ dc1 }}" |
| 29 |
name: "{{ virtual_machines[0].name }}" |
| 30 |
folder: "{{ virtual_machines[0].folder }}" |
| 31 |
state: present |
| 32 |
snapshot_name: "snap_{{item}}" |
| 33 |
description: "snap named {{item}}" |
| 34 |
with_items: |
| 35 |
- a |
| 36 |
- b |
| 37 |
|
| 38 |
# Test0003: Reanme a to c |
| 39 |
- name: 0003 - Rename snapshot |
| 40 |
community.vmware.vmware_guest_snapshot: |
| 41 |
validate_certs: false |
| 42 |
hostname: '{{ vcenter_hostname }}' |
| 43 |
username: '{{ vcenter_username }}' |
| 44 |
password: '{{ vcenter_password }}' |
| 45 |
datacenter: "{{ dc1 }}" |
| 46 |
name: "{{ virtual_machines[0].name }}" |
| 47 |
folder: "{{ virtual_machines[0].folder }}" |
| 48 |
state: present |
| 49 |
snapshot_name: snap_a |
| 50 |
new_snapshot_name: snap_c |
| 51 |
|
| 52 |
# Test0004: Create snap_a again |
| 53 |
- name: 0004 - Re-create snapshot a |
| 54 |
community.vmware.vmware_guest_snapshot: |
| 55 |
validate_certs: false |
| 56 |
hostname: '{{ vcenter_hostname }}' |
| 57 |
username: '{{ vcenter_username }}' |
| 58 |
password: '{{ vcenter_password }}' |
| 59 |
datacenter: "{{ dc1 }}" |
| 60 |
name: "{{ virtual_machines[0].name }}" |
| 61 |
folder: "{{ virtual_machines[0].folder }}" |
| 62 |
state: present |
| 63 |
snapshot_name: snap_a |
| 64 |
description: "snap named a" |
| 65 |
|
| 66 |
# Test0005: Change description of snap_c |
| 67 |
- name: 0005 - Change description of snap_c |
| 68 |
community.vmware.vmware_guest_snapshot: |
| 69 |
validate_certs: false |
| 70 |
hostname: '{{ vcenter_hostname }}' |
| 71 |
username: '{{ vcenter_username }}' |
| 72 |
password: '{{ vcenter_password }}' |
| 73 |
datacenter: "{{ dc1 }}" |
| 74 |
name: "{{ virtual_machines[0].name }}" |
| 75 |
folder: "{{ virtual_machines[0].folder }}" |
| 76 |
state: present |
| 77 |
snapshot_name: snap_c |
| 78 |
new_description: "renamed to snap_c from snap_a" |
| 79 |
|
| 80 |
# Test0006: Delete snap_b with child remove |
| 81 |
- name: 0006 - Delete snap_b with child remove |
| 82 |
community.vmware.vmware_guest_snapshot: |
| 83 |
validate_certs: false |
| 84 |
hostname: '{{ vcenter_hostname }}' |
| 85 |
username: '{{ vcenter_username }}' |
| 86 |
password: '{{ vcenter_password }}' |
| 87 |
datacenter: "{{ dc1 }}" |
| 88 |
name: "{{ virtual_machines[0].name }}" |
| 89 |
folder: "{{ virtual_machines[0].folder }}" |
| 90 |
state: absent |
| 91 |
snapshot_name: snap_b |
| 92 |
remove_children: true |
| 93 |
|
| 94 |
# Test0007: Delete all snapshots |
| 95 |
- name: 0007 - Delete all snapshots |
| 96 |
community.vmware.vmware_guest_snapshot: |
| 97 |
validate_certs: false |
| 98 |
hostname: '{{ vcenter_hostname }}' |
| 99 |
username: '{{ vcenter_username }}' |
| 100 |
password: '{{ vcenter_password }}' |
| 101 |
datacenter: "{{ dc1 }}" |
| 102 |
name: "{{ virtual_machines[0].name }}" |
| 103 |
folder: "{{ virtual_machines[0].folder }}" |
| 104 |
state: remove_all |
| 105 |
|
| 106 |
# Test0008: Create snap_a again and revert to it |
| 107 |
- name: 0008 - Re-create snapshot a |
| 108 |
community.vmware.vmware_guest_snapshot: |
| 109 |
validate_certs: false |
| 110 |
hostname: '{{ vcenter_hostname }}' |
| 111 |
username: '{{ vcenter_username }}' |
| 112 |
password: '{{ vcenter_password }}' |
| 113 |
datacenter: "{{ dc1 }}" |
| 114 |
name: "{{ virtual_machines[0].name }}" |
| 115 |
folder: "{{ virtual_machines[0].folder }}" |
| 116 |
state: present |
| 117 |
snapshot_name: snap_a |
| 118 |
description: "snap named a" |
| 119 |
|
| 120 |
- name: 0008 - Revert to snap_a |
| 121 |
community.vmware.vmware_guest_snapshot: |
| 122 |
validate_certs: false |
| 123 |
hostname: '{{ vcenter_hostname }}' |
| 124 |
username: '{{ vcenter_username }}' |
| 125 |
password: '{{ vcenter_password }}' |
| 126 |
datacenter: "{{ dc1 }}" |
| 127 |
name: "{{ virtual_machines[0].name }}" |
| 128 |
folder: "{{ virtual_machines[0].folder }}" |
| 129 |
state: revert |
| 130 |
snapshot_name: snap_a |
| 131 |
|
| 132 |
# Test0009: Create snap_a and check in result |
| 133 |
- name: 0009 - create snapshot a |
| 134 |
community.vmware.vmware_guest_snapshot: |
| 135 |
validate_certs: false |
| 136 |
hostname: '{{ vcenter_hostname }}' |
| 137 |
username: '{{ vcenter_username }}' |
| 138 |
password: '{{ vcenter_password }}' |
| 139 |
datacenter: "{{ dc1 }}" |
| 140 |
name: "{{ virtual_machines[0].name }}" |
| 141 |
folder: "{{ virtual_machines[0].folder }}" |
| 142 |
state: present |
| 143 |
snapshot_name: snap_a |
| 144 |
description: "snap named a" |
| 145 |
register: snapshot_details |
| 146 |
|
| 147 |
- ansible.builtin.debug: var=snapshot_details |
| 148 |
|
| 149 |
- name: Check if snapshot details available or not |
| 150 |
ansible.builtin.assert: |
| 151 |
that: |
| 152 |
- "snapshot_details['msg'] == 'Snapshot named [snap_a] already exists and is current.'" |
| 153 |
|
| 154 |
# Test0011: Failure sceanrios - when name and UUID is not specified |
| 155 |
- name: 0011 - name and UUID is missing |
| 156 |
community.vmware.vmware_guest_snapshot: |
| 157 |
validate_certs: false |
| 158 |
hostname: '{{ vcenter_hostname }}' |
| 159 |
username: '{{ vcenter_username }}' |
| 160 |
password: '{{ vcenter_password }}' |
| 161 |
datacenter: "{{ dc1 }}" |
| 162 |
state: present |
| 163 |
snapshot_name: snap_a |
| 164 |
description: "snap named a" |
| 165 |
register: snapshot_failure_details |
| 166 |
ignore_errors: true |
| 167 |
|
| 168 |
- name: Check if error is shown |
| 169 |
ansible.builtin.assert: |
| 170 |
that: |
| 171 |
- "'one of the following is required: name, uuid' in snapshot_failure_details['msg']" |
| 172 |
- "snapshot_failure_details.changed == false" |
| 173 |
|
| 174 |
# Test0010 : Test for revert and remove a snapshot to specify snapshot_id |
| 175 |
- name: 0012 - Create snapshot |
| 176 |
community.vmware.vmware_guest_snapshot: |
| 177 |
validate_certs: false |
| 178 |
hostname: '{{ vcenter_hostname }}' |
| 179 |
username: '{{ vcenter_username }}' |
| 180 |
password: '{{ vcenter_password }}' |
| 181 |
datacenter: "{{ dc1 }}" |
| 182 |
name: "{{ virtual_machines[0].name }}" |
| 183 |
folder: "{{ virtual_machines[0].folder }}" |
| 184 |
state: present |
| 185 |
snapshot_name: "snap_{{item}}" |
| 186 |
description: "snap named {{item}}" |
| 187 |
with_items: |
| 188 |
- b |
| 189 |
- c |
| 190 |
register: snapshot_creation_result0012 |
| 191 |
|
| 192 |
- name: Create the snapshot_ids variable |
| 193 |
ansible.builtin.set_fact: |
| 194 |
snapshot_ids: >- |
| 195 |
{{ snapshot_ids | default([]) |
| 196 |
+ [({ |
| 197 |
'name': item.snapshot_results.current_snapshot.name, |
| 198 |
'snapshot_id': item.snapshot_results.current_snapshot.id |
| 199 |
})] |
| 200 |
}} |
| 201 |
loop: "{{ snapshot_creation_result0012.results }}" |
| 202 |
|
| 203 |
- name: 0013 - Revert to snap_b with snapshot_id |
| 204 |
community.vmware.vmware_guest_snapshot: |
| 205 |
validate_certs: false |
| 206 |
hostname: '{{ vcenter_hostname }}' |
| 207 |
username: '{{ vcenter_username }}' |
| 208 |
password: '{{ vcenter_password }}' |
| 209 |
datacenter: "{{ dc1 }}" |
| 210 |
name: "{{ virtual_machines[0].name }}" |
| 211 |
folder: "{{ virtual_machines[0].folder }}" |
| 212 |
state: revert |
| 213 |
snapshot_id: "{{ item.snapshot_id }}" |
| 214 |
loop: "{{ snapshot_ids }}" |
| 215 |
when: |
| 216 |
- item.name == "snap_b" |
| 217 |
register: revert_snapshot_with_id_result |
| 218 |
|
| 219 |
- name: Make sure whether reverted with snapshot_id |
| 220 |
ansible.builtin.assert: |
| 221 |
that: |
| 222 |
- item.changed is sameas true |
| 223 |
loop: "{{ revert_snapshot_with_id_result.results }}" |
| 224 |
when: |
| 225 |
- item.item.name == "snap_b" |
| 226 |
|
| 227 |
- name: 0014 - Remove snap_b with snapshot_id |
| 228 |
community.vmware.vmware_guest_snapshot: |
| 229 |
validate_certs: false |
| 230 |
hostname: '{{ vcenter_hostname }}' |
| 231 |
username: '{{ vcenter_username }}' |
| 232 |
password: '{{ vcenter_password }}' |
| 233 |
datacenter: "{{ dc1 }}" |
| 234 |
name: "{{ virtual_machines[0].name }}" |
| 235 |
folder: "{{ virtual_machines[0].folder }}" |
| 236 |
state: absent |
| 237 |
snapshot_id: "{{ item.snapshot_id }}" |
| 238 |
loop: "{{ snapshot_ids }}" |
| 239 |
when: |
| 240 |
- item.name == "snap_b" |
| 241 |
register: remove_snapshot_with_id_result |
| 242 |
|
| 243 |
- name: Make sure whether removed with snapshot_id |
| 244 |
ansible.builtin.assert: |
| 245 |
that: |
| 246 |
- item.changed is sameas true |
| 247 |
loop: "{{ remove_snapshot_with_id_result.results }}" |
| 248 |
when: |
| 249 |
- item.item.name == "snap_b" |