- Added `bootstrap_sparrowdo` role for bootstrapping Sparrowdo on a VM. - Introduced `cleanup_vm` role for cleaning up VMs and disk images. - Created `download_image` role to download and cache QCOW2 images. - Developed `golden_image` role for creating and customizing golden images. - Implemented `provision_vm` role for provisioning VMs as linked clones. - Added `run_test` role for executing tests with Sparrowdo. - Created playbooks for building golden images, running single tests, and running test suites. - Enhanced documentation with usage examples, configuration details, and troubleshooting tips. - Added support for multiple cloud providers (AWS, Azure) in the test execution workflow. Signed-off-by: Stephen Simpson <ssimpson89@users.noreply.github.com>
78 lines
2.2 KiB
YAML
78 lines
2.2 KiB
YAML
---
|
|
# Tasks for cleanup_vm role
|
|
|
|
- name: Cleanup single VM
|
|
when: vm_name != ""
|
|
block:
|
|
- name: Display cleanup info for single VM
|
|
debug:
|
|
msg: "Starting cleanup for VM: {{ vm_name }}"
|
|
|
|
- name: Destroy VM
|
|
command: virsh -c qemu:///system destroy {{ vm_name }}
|
|
become: true
|
|
register: destroy_result
|
|
failed_when: false
|
|
changed_when: destroy_result.rc == 0
|
|
|
|
- name: Display destroy result
|
|
debug:
|
|
msg: "{{ 'VM was not running' if destroy_result.rc != 0 else 'VM destroyed' }}"
|
|
|
|
- name: Undefine VM
|
|
command: virsh -c qemu:///system undefine {{ vm_name }}
|
|
become: true
|
|
register: undefine_result
|
|
failed_when: false
|
|
changed_when: undefine_result.rc == 0
|
|
|
|
- name: Display undefine result
|
|
debug:
|
|
msg: "{{ 'VM definition already removed' if undefine_result.rc != 0 else 'VM undefined' }}"
|
|
|
|
- name: Remove disk image
|
|
file:
|
|
path: "/var/lib/libvirt/images/{{ vm_name }}.qcow2"
|
|
state: absent
|
|
become: true
|
|
when: remove_disk
|
|
|
|
- name: Display cleanup completion
|
|
debug:
|
|
msg: "Cleanup complete for {{ vm_name }}"
|
|
|
|
- name: Cleanup VMs matching pattern
|
|
when: cleanup_pattern != ""
|
|
block:
|
|
- name: Get list of VMs matching pattern
|
|
shell: virsh -c qemu:///system list --all --name | grep -E "{{ cleanup_pattern }}"
|
|
become: true
|
|
register: matching_vms
|
|
failed_when: false
|
|
changed_when: false
|
|
|
|
- name: Display matching VMs
|
|
debug:
|
|
msg: "Found {{ matching_vms.stdout_lines | length }} VMs matching pattern: {{ cleanup_pattern }}"
|
|
when: matching_vms.stdout_lines | length > 0
|
|
|
|
- name: Cleanup each matching VM
|
|
include_tasks: cleanup_single.yml
|
|
loop: "{{ matching_vms.stdout_lines }}"
|
|
loop_control:
|
|
loop_var: vm_to_cleanup
|
|
when: matching_vms.stdout_lines | length > 0
|
|
|
|
- name: Cleanup VMs from list
|
|
when: cleanup_vm_list | length > 0
|
|
block:
|
|
- name: Display VMs to cleanup
|
|
debug:
|
|
msg: "Cleaning up {{ cleanup_vm_list | length }} VMs from list"
|
|
|
|
- name: Cleanup each VM in list
|
|
include_tasks: cleanup_single.yml
|
|
loop: "{{ cleanup_vm_list }}"
|
|
loop_control:
|
|
loop_var: vm_to_cleanup
|