mirror-env/roles/vm-qemu/tasks/vm.yml

57 lines
2.3 KiB
YAML

---
# quite a lot of duplication, probably fix later
# Gather info
- name: "{{vm.name}} - Check if vm was created already"
stat:
path: "{{userdata}}/{{vm.name}}"
register: vmexists
ignore_errors: true
- name: "{{vm.name}} - Check for ubuntu iso"
stat:
path: "{{role_path}}/files/ubuntu20_04.iso"
register: isoexists
ignore_errors: true
- name: "{{vm.name}} - Check for ubuntu iso seed"
stat:
path: "{{userdata}}/{{vm.name}}/seed.iso"
register: seedexists
ignore_errors: true
# Setting up VM
- name: "{{vm.name}} - Create directory for VM"
file:
state: directory
path: "{{userdata}}/{{vm.name}}"
when: vmexists.stat.exists == false
# didn't use get_url module since it broke with symlinks
- name: "{{vm.name}} - Fetching ubuntu iso"
command: curl -o "{{role_path}}/files/ubuntu20_04.iso" https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-live-server-amd64.iso
when: isoexists.stat.exists == false
- name: "{{vm.name}} - Create disk images"
shell:
cmd: "for i in {1..6}; do qemu-img create -f qcow2 {{userdata}}/{{vm.name}}/drive${i} {{vm.disk_size}}; done"
when: vmexists.stat.exists == false
- name: "{{vm.name}} - Creating cloud-init iso"
command: "genisoimage -output {{userdata}}/{{vm.name}}/seed.iso -volid cidata -joliet -rock {{role_path}}/files/user-data {{role_path}}/files/meta-data"
when: seedexists.stat.exists == false
- name: "{{vm.name}} - Starting autoinstallation"
shell:
cmd: "qemu-system-x86_64 -cdrom {{role_path}}/files/ubuntu20_04.iso \
-enable-kvm -boot order=d \
-drive file={{userdata}}/{{vm.name}}/drive1,if=virtio,id=a,media=disk,format=qcow2 \
-drive file={{userdata}}/{{vm.name}}/drive2,if=virtio,id=b,media=disk,format=qcow2 \
-drive file={{userdata}}/{{vm.name}}/drive3,if=virtio,id=c,media=disk,format=qcow2 \
-drive file={{userdata}}/{{vm.name}}/drive4,if=virtio,id=d,media=disk,format=qcow2 \
-drive file={{userdata}}/{{vm.name}}/drive5,if=virtio,id=e,media=disk,format=qcow2 \
-drive file={{userdata}}/{{vm.name}}/drive6,if=virtio,id=f,media=disk,format=qcow2 \
-drive file={{userdata}}/{{vm.name}}/seed.iso,if=virtio,format=raw \
-bios {{ovmf}} \
-m {{vm.ram}}"
# todo: find a way to not ask for confirmation to start autoinstall
# bug: autoinstall will not shutdown properly so the ansible task will never finish