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
This commit is contained in:
parent
e55b331d2d
commit
d625057b7a
@ -38,22 +38,41 @@
|
|||||||
|
|
||||||
- name: Delete VM LV
|
- name: Delete VM LV
|
||||||
lvol:
|
lvol:
|
||||||
vg: vg01
|
vg: "{{ default_vm_disk_vg }}"
|
||||||
lv: "{{ hostvars[item]['server_hostname'] }}"
|
lv: "{{ hostvars[item]['server_hostname'] }}"
|
||||||
state: absent
|
state: absent
|
||||||
force: yes
|
force: yes
|
||||||
failed_when: false
|
failed_when: false
|
||||||
when:
|
when:
|
||||||
- hostvars[item]['server_vm'] | default(false) | bool
|
- 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'] }}"
|
with_items: "{{ groups['pxe_servers'] }}"
|
||||||
|
|
||||||
- name: Create VM LV
|
- name: Create VM LV
|
||||||
lvol:
|
lvol:
|
||||||
vg: vg01
|
vg: "{{ default_vm_disk_vg }}"
|
||||||
lv: "{{ hostvars[item]['server_hostname'] }}"
|
lv: "{{ hostvars[item]['server_hostname'] }}"
|
||||||
size: "{{ default_vm_storage }}"
|
size: "{{ default_vm_storage }}"
|
||||||
when:
|
when:
|
||||||
- hostvars[item]['server_vm'] | default(false) | bool
|
- 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'] }}"
|
with_items: "{{ groups['pxe_servers'] }}"
|
||||||
|
|
||||||
- name: Create the VM template
|
- name: Create the VM template
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
default_interface: "{{ default_network | default('eth0') }}"
|
default_interface: "{{ default_network | default('eth0') }}"
|
||||||
default_vm_image: "{{ default_image | default('ubuntu-16.04-amd64') }}"
|
default_vm_image: "{{ default_image | default('ubuntu-16.04-amd64') }}"
|
||||||
default_vm_storage: "{{ vm_disk_size | default(92160) }}"
|
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_acng_bind_address: 0.0.0.0
|
||||||
default_os_families:
|
default_os_families:
|
||||||
ubuntu-16.04-amd64: debian
|
ubuntu-16.04-amd64: debian
|
||||||
@ -26,7 +28,7 @@ default_ubuntu_mirror_directory: /ubuntu
|
|||||||
|
|
||||||
default_container_tech: "{{ container_tech | default('lxc') }}"
|
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
|
# IP address, or domain name of the TFTP server
|
||||||
tftp_server: "{{ hostvars[groups['pxe_hosts'][0]]['ansible_host'] | default(ansible_host) }}"
|
tftp_server: "{{ hostvars[groups['pxe_hosts'][0]]['ansible_host'] | default(ansible_host) }}"
|
||||||
|
@ -34,9 +34,15 @@
|
|||||||
</pm>
|
</pm>
|
||||||
<devices>
|
<devices>
|
||||||
<emulator>/usr/bin/kvm-spice</emulator>
|
<emulator>/usr/bin/kvm-spice</emulator>
|
||||||
|
{% if default_vm_disk_mode == "lvm" %}
|
||||||
<disk type='block' device='disk'>
|
<disk type='block' device='disk'>
|
||||||
<driver name='qemu' type='raw' cache='none' io='native'/>
|
<driver name='qemu' type='raw' cache='none' io='native'/>
|
||||||
<source dev='/dev/vg01/{{ hostvars[item]["server_hostname"] }}'/>
|
<source dev='/dev/{{ default_vm_disk_vg }}/{{ hostvars[item]["server_hostname"] }}'/>
|
||||||
|
{% elif default_vm_disk_mode == "file" %}
|
||||||
|
<disk type='file' device='disk'>
|
||||||
|
<driver name='qemu' type='qcow2' cache='none' io='native'/>
|
||||||
|
<source file='/var/lib/libvirt/images/{{ hostvars[item]["server_hostname"] }}.img'/>
|
||||||
|
{% endif %}
|
||||||
<target dev='vda' bus='virtio'/>
|
<target dev='vda' bus='virtio'/>
|
||||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
|
||||||
<boot order='1'/>
|
<boot order='1'/>
|
||||||
|
@ -174,6 +174,8 @@
|
|||||||
- name: Locate data volume
|
- name: Locate data volume
|
||||||
command: "vgdisplay vg01"
|
command: "vgdisplay vg01"
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
when:
|
||||||
|
- default_vm_disk_mode | default('lvm') == "lvm"
|
||||||
register: data_volume
|
register: data_volume
|
||||||
|
|
||||||
- name: Locate data disk
|
- 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}'
|
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
|
register: lsblk
|
||||||
when:
|
when:
|
||||||
|
- default_vm_disk_mode | default('lvm') == "lvm"
|
||||||
- data_volume.rc != 0
|
- data_volume.rc != 0
|
||||||
- mnaio_data_disk is undefined
|
- mnaio_data_disk is undefined
|
||||||
|
|
||||||
- name: Create data disk label
|
- name: Create data disk label
|
||||||
command: "parted --script /dev/{{ mnaio_data_disk | default(lsblk.stdout) }} mklabel gpt"
|
command: "parted --script /dev/{{ mnaio_data_disk | default(lsblk.stdout) }} mklabel gpt"
|
||||||
when:
|
when:
|
||||||
|
- default_vm_disk_mode | default('lvm') == "lvm"
|
||||||
- data_volume.rc != 0
|
- data_volume.rc != 0
|
||||||
|
|
||||||
- name: Create data disk partition
|
- name: Create data disk partition
|
||||||
command: "parted --align optimal --script /dev/{{ mnaio_data_disk | default(lsblk.stdout) }} mkpart data1 ext4 0% 100%"
|
command: "parted --align optimal --script /dev/{{ mnaio_data_disk | default(lsblk.stdout) }} mkpart data1 ext4 0% 100%"
|
||||||
when:
|
when:
|
||||||
|
- default_vm_disk_mode | default('lvm') == "lvm"
|
||||||
- data_volume.rc != 0
|
- data_volume.rc != 0
|
||||||
|
|
||||||
- name: Create data volume group
|
- name: Create data volume group
|
||||||
@ -199,11 +204,14 @@
|
|||||||
vg: vg01
|
vg: vg01
|
||||||
pvs: "/dev/{{ mnaio_data_disk | default(lsblk.stdout) }}1"
|
pvs: "/dev/{{ mnaio_data_disk | default(lsblk.stdout) }}1"
|
||||||
when:
|
when:
|
||||||
|
- default_vm_disk_mode | default('lvm') == "lvm"
|
||||||
- data_volume.rc != 0
|
- data_volume.rc != 0
|
||||||
|
|
||||||
- name: Locate virsh data volume
|
- name: Locate virsh data volume
|
||||||
command: "virsh pool-info vg01"
|
command: "virsh pool-info vg01"
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
when:
|
||||||
|
- default_vm_disk_mode | default('lvm') == "lvm"
|
||||||
register: virsh_data_volume
|
register: virsh_data_volume
|
||||||
|
|
||||||
- name: Create /etc/libvirt/storage directory
|
- name: Create /etc/libvirt/storage directory
|
||||||
@ -218,6 +226,7 @@
|
|||||||
virsh pool-define /etc/libvirt/storage/vg01.xml
|
virsh pool-define /etc/libvirt/storage/vg01.xml
|
||||||
virsh pool-autostart vg01 || true
|
virsh pool-autostart vg01 || true
|
||||||
when:
|
when:
|
||||||
|
- default_vm_disk_mode | default('lvm') == "lvm"
|
||||||
- virsh_data_volume.rc != 0
|
- virsh_data_volume.rc != 0
|
||||||
|
|
||||||
- name: Load virtio kernel modules
|
- name: Load virtio kernel modules
|
||||||
|
Loading…
Reference in New Issue
Block a user