tronde / kvm_provision_lab Goto Github PK
View Code? Open in Web Editor NEWAnsible role that shows how to provision a lab envirionment on kvm hypervisor
Ansible role that shows how to provision a lab envirionment on kvm hypervisor
Currently this role supports connecting domains to the default network, only. That's due to the current code in the templates:
<interface type='network'>
<source network='{{ item.value.vm_net }}'/>
<model type='virtio'/>
<link state='up'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
With this code it's not possible to connect a domain to a network in bridged mode..
The <interface>
tag for a bridged network would look like:
<interface type='bridge'>
<source bridge='{{ item.value.vm_net }}'/>
<model type='virtio'/>
<link state='up'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
Maybe the <address type/>
and <alias name/>
are not even necessary in template file. I'll have to check on that.
To improve this role to enable it configuring domains to connect to bridged networks a new variable, e.g. if_type
, could be introduced carrying the network type [network|bridge]. So in the template files it would look like the following:
<interface type='{{ item.value.if_type }}'>
<source {{ item.value.if_type }}='{{ item.value.vm_net }}'/>
<model type='virtio'/>
<link state='up'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
---
- name: Provision Debian lab VMs
hosts: localhost
debugger: never
vars_files:
- roles/kvm_provision_lab/vars/debian11_with_2nd_disk.yml
tasks:
- name: Run role kvm_provision_lab
include_role:
name: kvm_provision_lab
---
libvirt_pool_dir: "/var/lib/libvirt/images"
vm_root_pass: "Password"
ssh_key: "ansible_id_rsa.pub"
guests:
debian-t1:
vm_ram_mb: 1024
vm_vcpus: 1
vm_net: default
os_type: debian11
file_type: qcow2
base_image_name: debian11-template
vm_template: "debian11-template"
second_hdd: true
second_hdd_size: 2G
I would have expected that the guest is created with a second disk of a useable size of 2 GiB.
The guest OS shows a usaable size of a few KiB for /dev/vdb
:
# lsblk /dev/vdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdb 254:16 0 192.5K 0 disk
The command qemu-img info /var/lib/libvirt/images/debian-t1-vdb.qcow2
shows it has a usable size of 2 GiB though:
$ qemu-img info /var/lib/libvirt/images/debian-t1-vdb.qcow2
image: /var/lib/libvirt/images/debian-t1-vdb.qcow2
file format: qcow2
virtual size: 2 GiB (2147483648 bytes)
disk size: 196 KiB
cluster_size: 65536
Format specific information:
compat: 1.1
compression type: zlib
lazy refcounts: false
refcount bits: 16
corrupt: false
extended l2: false
When an additional disk is created by running qemu-img create -q -f qcow2 /var/lib/libvirt/images/debian-t1-vdc.qcow2 2G
and attached to the VM it shows the correct size in guest OS:
# lsblk /dev/vd{b,c}
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vdb 254:16 0 192.5K 0 disk
vdc 254:32 0 2G 0 disk
And it gets weird:
$ qemu-img info /var/lib/libvirt/images/debian-t1-vdc.qcow2
image: /var/lib/libvirt/images/debian-t1-vdc.qcow2
file format: qcow2
virtual size: 2 GiB (2147483648 bytes)
disk size: 196 KiB
cluster_size: 65536
Format specific information:
compat: 1.1
compression type: zlib
lazy refcounts: false
refcount bits: 16
corrupt: false
extended l2: false
$ qemu-img compare /var/lib/libvirt/images/debian-t1-vdb.qcow2 /var/lib/libvirt/images/debian-t1-vdc.qcow2
Images are identical.
``
So far I have absolutely no clue and now idea what causes this. Help would be much appreciated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.