diff --git a/README.md b/README.md index 6d7f4c7..33f507f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ This script helps quickly set up a vm development environment for cs club's mirrors. ## VM Installation Option 1 (qmeu-vm.yml) + +**instructions need to be rewritten** + Install the following dependencies - qemu - genisoimage diff --git a/hosts b/hosts index ef40453..85a89ab 100755 --- a/hosts +++ b/hosts @@ -1,6 +1,17 @@ +[local] +localhost + +[vm] ubuntu@localhost -[all:vars] +[local:vars] +ansible_connection=local +vm_name=mirror-env +vm_mem=2G +vm_disk_size=10G +ovmf_location=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd + +[vm:vars] ansible_connection=ssh ansible_port=7777 ansible_user=ubuntu diff --git a/mirror-vm b/mirror-vm index 913ce21..b2a1c34 100755 --- a/mirror-vm +++ b/mirror-vm @@ -38,6 +38,9 @@ run-install: -bios ${ovmf_location} \ -m ${vm_mem} +post-install: + + run: qemu-system-x86_64 -enable-kvm -boot order=d \ -drive file=drive1,if=virtio,id=a,media=disk,format=qcow2 \ diff --git a/qemu-vm.yml b/qemu-vm.yml index e69de29..0e26d0c 100644 --- a/qemu-vm.yml +++ b/qemu-vm.yml @@ -0,0 +1,5 @@ +--- +- hosts: local + become: true + roles: + - qemu-vm diff --git a/meta-data b/roles/qemu-vm/files/meta-data similarity index 100% rename from meta-data rename to roles/qemu-vm/files/meta-data diff --git a/user-data b/roles/qemu-vm/files/user-data similarity index 100% rename from user-data rename to roles/qemu-vm/files/user-data diff --git a/roles/qemu-vm/tasks/main.yml b/roles/qemu-vm/tasks/main.yml new file mode 100644 index 0000000..7561e84 --- /dev/null +++ b/roles/qemu-vm/tasks/main.yml @@ -0,0 +1,48 @@ +--- +- name: "{{vm_name}} - Gathering info" + stat: + path: "{{playbook_dir}}/vm/{{vm_name}}" + register: vm_stat + +- name: "{{vm_name}} - Checking if VM already exists" + meta: end_play + when: vm_stat.stat.exists == true + +# Start vm install +- name: "{{vm_name}} - Create directory for VM" + file: + state: directory + path: "{{playbook_dir}}/vm/{{vm_name}}" + +- name: "{{vm_name}} - Create disk images" + shell: + cmd: "for i in {1..6}; do qemu-img create -f qcow2 {{playbook_dir}}/vm/{{vm_name}}/drive${i} {{vm_disk_size}}; done" + +- name: "{{vm_name}} - Creating cloud-init iso" + command: "genisoimage -output {{playbook_dir}}/vm/{{vm_name}}/seed.iso -volid cidata -joliet -rock {{role_path}}/files/user-data {{role_path}}/files/meta-data" + +# Autoinstall ubuntu on vm +- name: "{{vm-name}} - Check if iso exists" + stat: + path: "{{role_path}}/files/ubuntu20_04.iso" + register: iso_stat + +- name: "{{vm-name}} - Fetching ubuntu iso" + get_url: + url: https://releases.ubuntu.com/20.04.3/ubuntu-20.04.3-live-server-amd64.iso + dest: "{{role_path}}/files/ubuntu20_04.iso" + when: iso_stat.stat.exists == false + +- name: "{{vm_name}} - Starting VM install" + command: > + qemu-system-x86_64 -cdrom {{role_path}}/files/ubuntu20_04.iso -enable-kvm -boot order=d + -drive file={{playbook_dir}}/vm/{{vm_name}}/drive1,if=virtio,id=a,media=disk,format=qcow2 + -drive file={{playbook_dir}}/vm/{{vm_name}}/drive2,if=virtio,id=b,media=disk,format=qcow2 + -drive file={{playbook_dir}}/vm/{{vm_name}}/drive3,if=virtio,id=c,media=disk,format=qcow2 + -drive file={{playbook_dir}}/vm/{{vm_name}}/drive4,if=virtio,id=d,media=disk,format=qcow2 + -drive file={{playbook_dir}}/vm/{{vm_name}}/drive5,if=virtio,id=e,media=disk,format=qcow2 + -drive file={{playbook_dir}}/vm/{{vm_name}}/drive6,if=virtio,id=f,media=disk,format=qcow2 + -drive file={{playbook_dir}}/vm/{{vm_name}}/seed.iso,if=virtio,format=raw + -bios {{ovmf_location}} + -m {{vm_mem}} +