mirror-env/qemu/install.yml

81 lines
3.1 KiB
YAML
Raw Normal View History

---
2021-09-13 19:38:28 -04:00
# Gather info
2021-09-16 20:54:11 -04:00
- hosts: localhost
tasks:
2021-09-27 19:16:33 -04:00
# make this check for the actual drive* files probably
2021-09-16 20:54:11 -04:00
- name: Check if vm was created already
stat:
path: "{{userdata}}"
register: vmexists
ignore_errors: true
- name: Check for ubuntu iso
stat:
2021-09-25 23:52:25 -04:00
path: "{{playbook_dir}}/files/ubuntu20_04.iso"
2021-09-16 20:54:11 -04:00
register: isoexists
ignore_errors: true
2021-09-29 19:49:39 -04:00
- name: Check for seed iso
2021-09-16 20:54:11 -04:00
stat:
path: "{{userdata}}/seed.iso"
register: seedexists
ignore_errors: true
2021-09-29 19:49:39 -04:00
- name: Check for extracted linux kernel
stat:
path: "{{userdata}}/vmlinuz"
register: kernelexists
ignore_errors: true
- name: Check for extracted initrd
stat:
path: "{{userdata}}/initrd"
register: initrdexists
ignore_errors: true
2021-09-13 19:38:28 -04:00
2021-09-16 20:54:11 -04:00
# Setting up VM
- name: Create directory for VM
file:
state: directory
path: "{{userdata}}"
when: vmexists.stat.exists == false
2021-09-13 19:38:28 -04:00
2021-09-16 20:54:11 -04:00
# didn't use get_url module since it broke with symlinks
- name: Fetching ubuntu iso
2021-09-25 23:52:25 -04:00
command: curl -o "{{playbook_dir}}/files/ubuntu20_04.iso" https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-live-server-amd64.iso
2021-09-16 20:54:11 -04:00
when: isoexists.stat.exists == false
2021-09-13 19:38:28 -04:00
2021-09-27 19:16:33 -04:00
- name: "Create disk images"
2021-09-16 20:54:11 -04:00
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
2021-09-13 19:38:28 -04:00
2021-09-16 20:54:11 -04:00
- name: Creating cloud-init iso
2021-09-25 23:52:25 -04:00
command: "genisoimage -output {{userdata}}/seed.iso -volid cidata -joliet -rock {{playbook_dir}}/files/user-data {{playbook_dir}}/files/meta-data"
2021-09-16 20:54:11 -04:00
when: seedexists.stat.exists == false
2021-09-13 19:38:28 -04:00
2021-09-29 19:49:39 -04:00
- name: Extracting linux kernel from iso
shell:
cmd: "isoinfo -i {{playbook_dir}}/files/ubuntu20_04.iso -R -x /casper/vmlinuz > {{userdata}}/vmlinuz"
when: kernelexists.stat.exists == false
- name: Extracting initrd from iso
shell:
cmd: "isoinfo -i {{playbook_dir}}/files/ubuntu20_04.iso -R -x /casper/initrd > {{userdata}}/initrd"
when: initrdexists.stat.exists == false
2021-09-16 20:54:11 -04:00
- name: Starting autoinstallation
shell:
2021-09-25 23:52:25 -04:00
cmd: "qemu-system-x86_64 -cdrom {{playbook_dir}}/files/ubuntu20_04.iso \
2021-09-16 20:54:11 -04:00
-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}} \
2021-09-29 19:49:39 -04:00
-m {{vm_ram}} \
-kernel {{userdata}}/vmlinuz \
-initrd {{userdata}}/initrd \
-append autoinstall"
2021-09-13 19:38:28 -04:00
2021-10-03 17:28:34 -04:00
# bug: autoinstall will not shutdown properly so the ansible task will never finish