Implement Ansible roles for Rocky Linux Testing Framework
- 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>
This commit is contained in:
17
ansible/roles/cleanup_vm/defaults/main.yml
Normal file
17
ansible/roles/cleanup_vm/defaults/main.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
# Default variables for cleanup_vm role
|
||||
|
||||
# VM name to cleanup (required)
|
||||
vm_name: ""
|
||||
|
||||
# Force destroy even if running
|
||||
force_destroy: true
|
||||
|
||||
# Remove disk image
|
||||
remove_disk: true
|
||||
|
||||
# Cleanup multiple VMs matching pattern
|
||||
cleanup_pattern: ""
|
||||
|
||||
# Cleanup all VMs in list
|
||||
cleanup_vm_list: []
|
||||
23
ansible/roles/cleanup_vm/tasks/cleanup_single.yml
Normal file
23
ansible/roles/cleanup_vm/tasks/cleanup_single.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
# Cleanup a single VM (used in loop)
|
||||
|
||||
- name: Destroy VM {{ vm_to_cleanup }}
|
||||
command: virsh -c qemu:///system destroy {{ vm_to_cleanup }}
|
||||
become: true
|
||||
register: destroy_result
|
||||
failed_when: false
|
||||
changed_when: destroy_result.rc == 0
|
||||
|
||||
- name: Undefine VM {{ vm_to_cleanup }}
|
||||
command: virsh -c qemu:///system undefine {{ vm_to_cleanup }}
|
||||
become: true
|
||||
register: undefine_result
|
||||
failed_when: false
|
||||
changed_when: undefine_result.rc == 0
|
||||
|
||||
- name: Remove disk for VM {{ vm_to_cleanup }}
|
||||
file:
|
||||
path: "/var/lib/libvirt/images/{{ vm_to_cleanup }}.qcow2"
|
||||
state: absent
|
||||
become: true
|
||||
when: remove_disk
|
||||
77
ansible/roles/cleanup_vm/tasks/main.yml
Normal file
77
ansible/roles/cleanup_vm/tasks/main.yml
Normal file
@@ -0,0 +1,77 @@
|
||||
---
|
||||
# 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
|
||||
Reference in New Issue
Block a user