From f72458a7b65b8c9c23df3a0a4a0d2531d7ba9b16 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Mon, 27 Sep 2021 19:16:33 -0400 Subject: [PATCH] fix qemu vm not installing --- group_vars/all.yml | 9 +++++---- qemu/main.yml | 3 ++- qemu/run.yml | 36 +++++++++++++++++++----------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/group_vars/all.yml b/group_vars/all.yml index 9f737f2..caf733b 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -1,6 +1,7 @@ --- -ovmf: -vm_ram: 1G -vm_disk_size: 9G -vm_ssh_port: 22 +# set this depending on your system +ovmf: /usr/share/edk2-ovmf/x64/OVMF_CODE.fd +vm_ram: 3G +vm_disk_size: 10G +vm_ssh_port: 7777 # vm doesn't seem to start with 22, leaving this here for now userdata: "{{playbook_dir}}/userdata" diff --git a/qemu/main.yml b/qemu/main.yml index 4eba108..84095e6 100644 --- a/qemu/main.yml +++ b/qemu/main.yml @@ -2,6 +2,7 @@ # Gather info - hosts: localhost tasks: + # make this check for the actual drive* files probably - name: Check if vm was created already stat: path: "{{userdata}}" @@ -30,7 +31,7 @@ command: curl -o "{{playbook_dir}}/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: Create disk images + - name: "Create disk images" shell: cmd: "for i in {1..6}; do qemu-img create -f qcow2 {{userdata}}/drive${i} {{vm_disk_size}}; done" when: vmexists.stat.exists == false diff --git a/qemu/run.yml b/qemu/run.yml index ca2cadb..5231115 100644 --- a/qemu/run.yml +++ b/qemu/run.yml @@ -1,18 +1,20 @@ --- -- name: Start VM - # async: 10000 - # poll: 0 - shell: - cmd: "qemu-system-x86_64 \ - -enable-kvm -boot order=d \ - -drive file={{userdata}}/drive1,if=virtio,id=a,media=disk,format=qcow2 \ - -drive file={{userdata}}/drive2,if=virtio,id=b,media=disk,format=qcow2 \ - -drive file={{userdata}}/drive3,if=virtio,id=c,media=disk,format=qcow2 \ - -drive file={{userdata}}/drive4,if=virtio,id=d,media=disk,format=qcow2 \ - -drive file={{userdata}}/drive5,if=virtio,id=e,media=disk,format=qcow2 \ - -drive file={{userdata}}/drive6,if=virtio,id=f,media=disk,format=qcow2 \ - -drive file={{userdata}}/seed.iso,if=virtio,format=raw \ - -bios {{ovmf}} \ - -m {{vm_ram}} \ - -net user,hostfwd=tcp::{{vm_ssh_port}}-:22 \ - -net nic" +- hosts: localhost + tasks: + - name: Start VM + # async: 10000 + # poll: 0 + shell: + cmd: "qemu-system-x86_64 \ + -enable-kvm -boot order=d \ + -drive file={{userdata}}/drive1,if=virtio,id=a,media=disk,format=qcow2 \ + -drive file={{userdata}}/drive2,if=virtio,id=b,media=disk,format=qcow2 \ + -drive file={{userdata}}/drive3,if=virtio,id=c,media=disk,format=qcow2 \ + -drive file={{userdata}}/drive4,if=virtio,id=d,media=disk,format=qcow2 \ + -drive file={{userdata}}/drive5,if=virtio,id=e,media=disk,format=qcow2 \ + -drive file={{userdata}}/drive6,if=virtio,id=f,media=disk,format=qcow2 \ + -drive file={{userdata}}/seed.iso,if=virtio,format=raw \ + -bios {{ovmf}} \ + -m {{vm_ram}} \ + -net user,hostfwd=tcp::{{vm_ssh_port}}-:22 \ + -net nic"