87 lines
3.2 KiB
YAML
87 lines
3.2 KiB
YAML
---
|
|
- name: Define image URLs
|
|
set_fact:
|
|
os_images:
|
|
coreos: "https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/44.20260510.3.1/x86_64/fedora-coreos-44.20260510.3.1-qemu.x86_64.qcow2.xz"
|
|
flatcar: "https://stable.release.flatcar-linux.net/amd64-usr/current/flatcar_production_qemu_image.img"
|
|
microos: "https://download.opensuse.org/tumbleweed/appliances/openSUSE-MicroOS.x86_64-ContainerHost-kvm-and-xen.qcow2"
|
|
|
|
- name: Verify internet connectivity
|
|
uri:
|
|
url: http://google.com
|
|
return_content: no
|
|
timeout: 10
|
|
|
|
- name: Download OS image
|
|
get_url:
|
|
url: "{{ os_images[os_type] }}"
|
|
dest: "{{ vm_images_dir }}/{{ vm_name }}.download"
|
|
mode: '0644'
|
|
become: yes
|
|
|
|
- name: Handle compressed or raw images
|
|
shell: |
|
|
DOWNLOAD_FILE="{{ vm_images_dir }}/{{ vm_name }}.download"
|
|
FINAL_FILE="{{ vm_images_dir }}/{{ vm_name }}"
|
|
|
|
# 1. Handle XZ compression
|
|
if [[ "{{ os_images[os_type] }}" == *.xz ]]; then
|
|
echo "Decompressing XZ image..."
|
|
unxz -c "$DOWNLOAD_FILE" > "$FINAL_FILE".qcow2
|
|
elif [[ "{{ os_images[os_type] }}" == *.img ]]; then
|
|
echo "Moving IMG image to final destination..."
|
|
mv "$DOWNLOAD_FILE" "$FINAL_FILE".img
|
|
else
|
|
echo "Moving QCOW2 image to final destination..."
|
|
mv "$DOWNLOAD_FILE" "$FINAL_FILE".qcow2
|
|
fi
|
|
rm -f "$DOWNLOAD_FILE"
|
|
become: yes
|
|
args:
|
|
creates: "{{ vm_images_dir }}/{{ vm_name }}.qcow2"
|
|
|
|
- name: Provision VM using virt-install
|
|
shell: |
|
|
{% if os_type == 'coreos' %}
|
|
virt-install \
|
|
--connect qemu:///system \
|
|
--name {{ vm_name }} \
|
|
--vcpus {{ cpu | default(default_cpu) }} \
|
|
--memory {{ ram | default(default_ram) }} \
|
|
--disk size={{ disk | default('10') }},backing_store={{ vm_images_dir }}/{{ vm_name }}.qcow2,backing_format=qcow2,bus=virtio \
|
|
--os-variant {{ os_variant }} \
|
|
--network network=default \
|
|
--graphics none \
|
|
--noautoconsole \
|
|
--boot uefi \
|
|
--sysinfo type=fwcfg,entry0.name=opt/com.coreos/config,entry0.file={{ vm_images_dir }}/{{ vm_name }}.ign
|
|
{% elif os_type == 'flatcar' %}
|
|
virt-install \
|
|
--connect qemu:///system \
|
|
--name {{ vm_name }} \
|
|
--vcpus {{ cpu | default(default_cpu) }} \
|
|
--memory {{ ram | default(default_ram) }} \
|
|
--disk path={{ vm_images_dir }}/{{ vm_name }}.img,format=qcow2,bus=virtio \
|
|
--import \
|
|
--os-variant {{ os_variant }} \
|
|
--network network=default \
|
|
--graphics none \
|
|
--noautoconsole \
|
|
--sysinfo system.serial=flatcar.first_boot=1 \
|
|
--qemu-commandline="-fw_cfg name=opt/org.flatcar-linux/config,file=/{{ vm_images_dir }}/{{ vm_name }}.ign"
|
|
{% elif os_type == 'microos' %}
|
|
virt-install \
|
|
--connect qemu:///system \
|
|
--name {{ vm_name }} \
|
|
--vcpus {{ cpu | default(default_cpu) }} \
|
|
--memory {{ ram | default(default_ram) }} \
|
|
--disk size={{ disk | default('10') }},backing_store={{ vm_images_dir }}/{{ vm_name }}.qcow2,backing_format=qcow2,bus=virtio \
|
|
--os-variant {{ os_variant }} \
|
|
--network network=default \
|
|
--graphics none \
|
|
--noautoconsole \
|
|
--boot uefi \
|
|
--sysinfo type=fwcfg,entry0.name=opt/com.coreos/config,entry0.file={{ vm_images_dir }}/{{ vm_name }}.ign
|
|
{% endif %}
|
|
args:
|
|
creates: "/etc/libvirt/qemu/{{ vm_name }}.xml" |