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:
18
ansible/roles/provision_vm/defaults/main.yml
Normal file
18
ansible/roles/provision_vm/defaults/main.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
# Default variables for provision_vm role
|
||||
# Most settings come from inventory (group_vars/libvirt.yml)
|
||||
|
||||
# VM name (required, passed from playbook/tasks)
|
||||
vm_name: ""
|
||||
|
||||
# Maximum wait time for IP (seconds)
|
||||
max_wait_ip: 30
|
||||
|
||||
# OS variant for virt-install
|
||||
os_variant: "rocky9-unknown"
|
||||
|
||||
# Use transient VM (doesn't survive reboot)
|
||||
vm_transient: true
|
||||
|
||||
# Return variable name for VM IP
|
||||
vm_ip_var: "provisioned_vm_ip"
|
||||
82
ansible/roles/provision_vm/tasks/main.yml
Normal file
82
ansible/roles/provision_vm/tasks/main.yml
Normal file
@@ -0,0 +1,82 @@
|
||||
---
|
||||
# Tasks for provision_vm role
|
||||
|
||||
- name: Validate VM name
|
||||
fail:
|
||||
msg: "vm_name is required"
|
||||
when: vm_name == ""
|
||||
|
||||
- name: Validate golden image path
|
||||
stat:
|
||||
path: "{{ golden_image_path }}"
|
||||
register: golden_image_stat
|
||||
failed_when: not golden_image_stat.stat.exists
|
||||
|
||||
- name: Set VM disk path
|
||||
set_fact:
|
||||
vm_disk_path: "/var/lib/libvirt/images/{{ vm_name }}.qcow2"
|
||||
|
||||
- name: Display provisioning info
|
||||
debug:
|
||||
msg: "Creating VM: {{ vm_name }}"
|
||||
|
||||
- name: Create linked clone overlay disk
|
||||
command: >
|
||||
qemu-img create -f qcow2
|
||||
-b {{ golden_image_path }}
|
||||
-F qcow2
|
||||
{{ vm_disk_path }}
|
||||
become: true
|
||||
register: disk_created
|
||||
changed_when: true
|
||||
|
||||
- name: Build virt-install command
|
||||
set_fact:
|
||||
virt_install_cmd: >
|
||||
virt-install
|
||||
--name {{ vm_name }}
|
||||
--memory {{ vm_memory }}
|
||||
--vcpus {{ vm_vcpus }}
|
||||
--disk path={{ vm_disk_path }},format=qcow2
|
||||
--import
|
||||
--os-variant {{ os_variant }}
|
||||
--network network={{ vm_network }}
|
||||
--noautoconsole
|
||||
--wait 0
|
||||
{% if vm_transient %}--transient{% endif %}
|
||||
|
||||
- name: Start VM with virt-install
|
||||
command: "{{ virt_install_cmd }}"
|
||||
become: true
|
||||
register: vm_started
|
||||
changed_when: true
|
||||
failed_when: vm_started.rc != 0
|
||||
|
||||
- name: Wait for VM to obtain IP address
|
||||
shell: >
|
||||
virsh -c qemu:///system domifaddr {{ vm_name }} --source lease 2>/dev/null |
|
||||
awk '/ipv4/ {print $4}' | cut -d/ -f1 | head -1
|
||||
become: true
|
||||
register: vm_ip_result
|
||||
until: vm_ip_result.stdout != "" and vm_ip_result.stdout != "0.0.0.0"
|
||||
retries: "{{ max_wait_ip }}"
|
||||
delay: 2
|
||||
changed_when: false
|
||||
|
||||
- name: Set VM IP fact
|
||||
set_fact:
|
||||
"{{ vm_ip_var }}": "{{ vm_ip_result.stdout }}"
|
||||
|
||||
- name: Display VM IP
|
||||
debug:
|
||||
msg: "IP obtained: {{ vm_ip_result.stdout }}"
|
||||
|
||||
- name: Export VM IP and name
|
||||
set_stats:
|
||||
data:
|
||||
"{{ vm_ip_var }}": "{{ vm_ip_result.stdout }}"
|
||||
provisioned_vm_name: "{{ vm_name }}"
|
||||
|
||||
- name: Register VM for cleanup
|
||||
set_fact:
|
||||
provisioned_vms: "{{ provisioned_vms | default([]) + [{'name': vm_name, 'ip': vm_ip_result.stdout, 'disk': vm_disk_path}] }}"
|
||||
Reference in New Issue
Block a user