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:
9
ansible/roles/bootstrap_sparrowdo/defaults/main.yml
Normal file
9
ansible/roles/bootstrap_sparrowdo/defaults/main.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
# Timeouts (seconds)
|
||||
vm_boot_timeout: 60
|
||||
ssh_port_timeout: 300
|
||||
bootstrap_timeout: 900
|
||||
|
||||
# VM resources
|
||||
vm_memory: 2048
|
||||
vm_vcpus: 2
|
||||
100
ansible/roles/bootstrap_sparrowdo/tasks/main.yml
Normal file
100
ansible/roles/bootstrap_sparrowdo/tasks/main.yml
Normal file
@@ -0,0 +1,100 @@
|
||||
---
|
||||
- name: Verify golden image exists
|
||||
stat:
|
||||
path: "{{ golden_image_path }}"
|
||||
register: golden_stat
|
||||
failed_when: not golden_stat.stat.exists
|
||||
|
||||
- name: Set bootstrap VM name
|
||||
set_fact:
|
||||
bootstrap_vm: "bootstrap-{{ ansible_date_time.epoch }}"
|
||||
|
||||
- name: Bootstrap Sparrowdo
|
||||
block:
|
||||
- name: Create overlay disk
|
||||
command: >
|
||||
qemu-img create -f qcow2
|
||||
-b {{ golden_image_path }} -F qcow2
|
||||
/var/lib/libvirt/images/{{ bootstrap_vm }}.qcow2
|
||||
become: true
|
||||
|
||||
- name: Start bootstrap VM
|
||||
command: >
|
||||
virt-install
|
||||
--name {{ bootstrap_vm }}
|
||||
--memory {{ vm_memory }}
|
||||
--vcpus {{ vm_vcpus }}
|
||||
--disk path=/var/lib/libvirt/images/{{ bootstrap_vm }}.qcow2,format=qcow2
|
||||
--import
|
||||
--os-variant rocky9-unknown
|
||||
--network network=default
|
||||
--noautoconsole
|
||||
--wait 0
|
||||
become: true
|
||||
|
||||
- name: Wait for VM IP
|
||||
shell: >
|
||||
virsh -c qemu:///system domifaddr {{ bootstrap_vm }} --source lease 2>/dev/null |
|
||||
awk '/ipv4/ {print $4}' | cut -d/ -f1 | head -1
|
||||
become: true
|
||||
register: vm_ip
|
||||
until: vm_ip.stdout != "" and vm_ip.stdout != "0.0.0.0"
|
||||
retries: "{{ vm_boot_timeout }}"
|
||||
delay: 2
|
||||
changed_when: false
|
||||
|
||||
- name: Wait for SSH
|
||||
wait_for:
|
||||
host: "{{ vm_ip.stdout }}"
|
||||
port: 22
|
||||
timeout: "{{ ssh_port_timeout }}"
|
||||
|
||||
- name: Run Sparrowdo bootstrap
|
||||
command:
|
||||
argv:
|
||||
- "~/.raku/bin/sparrowdo"
|
||||
- "--host={{ vm_ip.stdout }}"
|
||||
- "--ssh_user={{ ssh_user }}"
|
||||
- "--ssh_private_key={{ ssh_private_key_path }}"
|
||||
- "--bootstrap"
|
||||
timeout: "{{ bootstrap_timeout }}"
|
||||
register: bootstrap_result
|
||||
retries: 3
|
||||
delay: 5
|
||||
until: bootstrap_result.rc == 0
|
||||
|
||||
- name: Shutdown VM
|
||||
command: >
|
||||
ssh -i {{ ssh_private_key_path }}
|
||||
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
|
||||
{{ ssh_user }}@{{ vm_ip.stdout }} 'sudo shutdown -h now'
|
||||
ignore_errors: true
|
||||
|
||||
- name: Wait for shutdown
|
||||
shell: virsh -c qemu:///system list --name | grep -q "{{ bootstrap_vm }}"
|
||||
become: true
|
||||
register: vm_running
|
||||
until: vm_running.rc != 0
|
||||
retries: 30
|
||||
delay: 2
|
||||
failed_when: false
|
||||
|
||||
always:
|
||||
- name: Force stop VM if running
|
||||
command: "virsh -c qemu:///system destroy {{ bootstrap_vm }}"
|
||||
become: true
|
||||
ignore_errors: true
|
||||
changed_when: false
|
||||
|
||||
- name: Undefine VM
|
||||
command: "virsh -c qemu:///system undefine {{ bootstrap_vm }}"
|
||||
become: true
|
||||
ignore_errors: true
|
||||
changed_when: false
|
||||
|
||||
- name: Remove overlay disk
|
||||
file:
|
||||
path: "/var/lib/libvirt/images/{{ bootstrap_vm }}.qcow2"
|
||||
state: absent
|
||||
become: true
|
||||
ignore_errors: true
|
||||
Reference in New Issue
Block a user