working on qemu ansible playbook

autoautoinstall
Daniel Liu 1 year ago
parent 1f16debf42
commit 351098c3d4
  1. 3
      README.md
  2. 13
      hosts
  3. 3
      mirror-vm
  4. 5
      qemu-vm.yml
  5. 0
      roles/qemu-vm/files/meta-data
  6. 0
      roles/qemu-vm/files/user-data
  7. 48
      roles/qemu-vm/tasks/main.yml

@ -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

13
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

@ -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 \

@ -0,0 +1,5 @@
---
- hosts: local
become: true
roles:
- qemu-vm

@ -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}}
Loading…
Cancel
Save