From d625057b7a5206dee60219321f99e74c2bbfa160 Mon Sep 17 00:00:00 2001 From: Bjoern Teipel Date: Fri, 23 Mar 2018 21:28:38 -0500 Subject: [PATCH] Adding mnaio qemu file backends mnaio uses LVM as default VM disk backend but that requires a lot of available disk space. A alternative option, the qcow2 file based backend is added to take benefit of thin provisioning. This backend can be triggered by setting the override `default_vm_disk_mode` to `file` Change-Id: Iaf97fef601f656901b6913eaafb9a6c28d4b7ba6 --- multi-node-aio/playbooks/deploy-vms.yml | 23 +++++++++++++++++++-- multi-node-aio/playbooks/group_vars/all.yml | 4 +++- multi-node-aio/playbooks/kvm/kvm-vm.xml | 8 ++++++- multi-node-aio/playbooks/setup-host.yml | 9 ++++++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/multi-node-aio/playbooks/deploy-vms.yml b/multi-node-aio/playbooks/deploy-vms.yml index c733167f..3ddfeee8 100644 --- a/multi-node-aio/playbooks/deploy-vms.yml +++ b/multi-node-aio/playbooks/deploy-vms.yml @@ -38,22 +38,41 @@ - name: Delete VM LV lvol: - vg: vg01 + vg: "{{ default_vm_disk_vg }}" lv: "{{ hostvars[item]['server_hostname'] }}" state: absent force: yes failed_when: false when: - hostvars[item]['server_vm'] | default(false) | bool + - default_vm_disk_mode | default('lvm') == "lvm" + with_items: "{{ groups['pxe_servers'] }}" + + - name: Delete VM Disk Image + command: | + rm -f /var/lib/libvirt/images/{{ hostvars[item]['server_hostname'] }}.img + failed_when: false + when: + - hostvars[item]['server_vm'] | default(false) | bool + - default_vm_disk_mode | default('lvm') == "file" with_items: "{{ groups['pxe_servers'] }}" - name: Create VM LV lvol: - vg: vg01 + vg: "{{ default_vm_disk_vg }}" lv: "{{ hostvars[item]['server_hostname'] }}" size: "{{ default_vm_storage }}" when: - hostvars[item]['server_vm'] | default(false) | bool + - default_vm_disk_mode | default('lvm') == "lvm" + with_items: "{{ groups['pxe_servers'] }}" + + - name: Create VM Disk Image + command: | + qemu-img create -f qcow2 /var/lib/libvirt/images/{{ hostvars[item]['server_hostname'] }}.img {{ default_vm_storage }}m + when: + - hostvars[item]['server_vm'] | default(false) | bool + - default_vm_disk_mode | default('lvm') == "file" with_items: "{{ groups['pxe_servers'] }}" - name: Create the VM template diff --git a/multi-node-aio/playbooks/group_vars/all.yml b/multi-node-aio/playbooks/group_vars/all.yml index 7750d40b..a207c475 100644 --- a/multi-node-aio/playbooks/group_vars/all.yml +++ b/multi-node-aio/playbooks/group_vars/all.yml @@ -14,6 +14,8 @@ default_interface: "{{ default_network | default('eth0') }}" default_vm_image: "{{ default_image | default('ubuntu-16.04-amd64') }}" default_vm_storage: "{{ vm_disk_size | default(92160) }}" +default_vm_disk_mode: lvm +default_vm_disk_vg: vg01 default_acng_bind_address: 0.0.0.0 default_os_families: ubuntu-16.04-amd64: debian @@ -26,7 +28,7 @@ default_ubuntu_mirror_directory: /ubuntu default_container_tech: "{{ container_tech | default('lxc') }}" -ipxe_kernel_url: "{{ ipxe_kernel_url | default('http://boot.ipxe.org/ipxe.lkrn') }}" +ipxe_kernel_url: "http://boot.ipxe.org/ipxe.lkrn" # IP address, or domain name of the TFTP server tftp_server: "{{ hostvars[groups['pxe_hosts'][0]]['ansible_host'] | default(ansible_host) }}" diff --git a/multi-node-aio/playbooks/kvm/kvm-vm.xml b/multi-node-aio/playbooks/kvm/kvm-vm.xml index d8fa35ae..b7c55f32 100644 --- a/multi-node-aio/playbooks/kvm/kvm-vm.xml +++ b/multi-node-aio/playbooks/kvm/kvm-vm.xml @@ -34,9 +34,15 @@ /usr/bin/kvm-spice +{% if default_vm_disk_mode == "lvm" %} - + +{% elif default_vm_disk_mode == "file" %} + + + +{% endif %}
diff --git a/multi-node-aio/playbooks/setup-host.yml b/multi-node-aio/playbooks/setup-host.yml index a7c55afa..a51722d5 100644 --- a/multi-node-aio/playbooks/setup-host.yml +++ b/multi-node-aio/playbooks/setup-host.yml @@ -174,6 +174,8 @@ - name: Locate data volume command: "vgdisplay vg01" failed_when: false + when: + - default_vm_disk_mode | default('lvm') == "lvm" register: data_volume - name: Locate data disk @@ -181,17 +183,20 @@ lsblk -brndo NAME,TYPE,FSTYPE,RO,SIZE | awk '/d[b-z]+ disk +0/{ if ($4>m){m=$4; d=$1}}; END{print d}' register: lsblk when: + - default_vm_disk_mode | default('lvm') == "lvm" - data_volume.rc != 0 - mnaio_data_disk is undefined - name: Create data disk label command: "parted --script /dev/{{ mnaio_data_disk | default(lsblk.stdout) }} mklabel gpt" when: + - default_vm_disk_mode | default('lvm') == "lvm" - data_volume.rc != 0 - name: Create data disk partition command: "parted --align optimal --script /dev/{{ mnaio_data_disk | default(lsblk.stdout) }} mkpart data1 ext4 0% 100%" when: + - default_vm_disk_mode | default('lvm') == "lvm" - data_volume.rc != 0 - name: Create data volume group @@ -199,11 +204,14 @@ vg: vg01 pvs: "/dev/{{ mnaio_data_disk | default(lsblk.stdout) }}1" when: + - default_vm_disk_mode | default('lvm') == "lvm" - data_volume.rc != 0 - name: Locate virsh data volume command: "virsh pool-info vg01" failed_when: false + when: + - default_vm_disk_mode | default('lvm') == "lvm" register: virsh_data_volume - name: Create /etc/libvirt/storage directory @@ -218,6 +226,7 @@ virsh pool-define /etc/libvirt/storage/vg01.xml virsh pool-autostart vg01 || true when: + - default_vm_disk_mode | default('lvm') == "lvm" - virsh_data_volume.rc != 0 - name: Load virtio kernel modules