Strukturumbau

This commit is contained in:
Benedikt Wismans 2022-11-30 20:09:44 +01:00
parent 87c997cb5a
commit e0f2422584
16 changed files with 98 additions and 399 deletions

View File

@ -1,114 +0,0 @@
<domain type='kvm'>
<name>vhostxpm</name>
<uuid>15666f6a-c48b-49b1-a2f9-2b01193cb204</uuid>
<title>XIT Projektmanagement</title>
<memory unit='KiB'>6291456</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static' current='2'>4</vcpu>
<os>
<type arch='x86_64' machine='pc-i440fx-xenial'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<vmport state='off'/>
</features>
<cpu mode='custom' match='exact'>
<model fallback='allow'>Broadwell-noTSX-IBRS</model>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/bin/kvm-spice</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/vhostxpm.qcow2'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<target dev='hdb' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
<controller type='usb' index='0' model='ich9-ehci1'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='virtio-serial' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</controller>
<filesystem type='mount' accessmode='mapped'>
<source dir='/var/tomcatlib'/>
<target dir='/libshare'/>
<readonly/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</filesystem>
<filesystem type='mount' accessmode='mapped'>
<source dir='/var/www/html/SDW/public/fonts'/>
<target dir='/fontshare'/>
<readonly/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</filesystem>
<interface type='network'>
<mac address='52:54:00:40:dc:13'/>
<source network='default'/>
<model type='rtl8139'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='spice' autoport='yes'/>
<sound model='ich6'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<redirdev bus='usb' type='spicevmc'>
</redirdev>
<redirdev bus='usb' type='spicevmc'>
</redirdev>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</memballoon>
</devices>
</domain>

View File

@ -29,7 +29,7 @@ password: bobby
# ssh_key_root: /root/.ssh/id_rsa.pub
ssh_key_core: /home/core/.ssh/id_rsa.pub
vm_name: vhosttst
vm_name: vhosttst2
vm_vcpus: 2
vm_ram_mb: 4096
vm_net: default

View File

@ -1,8 +1,5 @@
---
- import_tasks: packages_install.yml
- import_tasks: script_upload.yml
- import_tasks: hosts_vm2ip.yml
...

View File

@ -1,200 +0,0 @@
<domain type='kvm' id='7'>
<name>template2204</name>
<uuid>b23e5e10-6e7b-4199-968d-8ee7c23ed636</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://ubuntu.com/ubuntu/20.04"/>
</libosinfo:libosinfo>
</metadata>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>2</vcpu>
<resource>
<partition>/machine</partition>
</resource>
<os>
<type arch='x86_64' machine='pc-q35-4.2'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
</features>
<cpu mode='custom' match='exact' check='full'>
<model fallback='forbid'>EPYC-IBPB</model>
<vendor>AMD</vendor>
<feature policy='require' name='x2apic'/>
<feature policy='require' name='tsc-deadline'/>
<feature policy='require' name='hypervisor'/>
<feature policy='require' name='tsc_adjust'/>
<feature policy='require' name='arch-capabilities'/>
<feature policy='require' name='xsaves'/>
<feature policy='require' name='cmp_legacy'/>
<feature policy='require' name='perfctr_core'/>
<feature policy='require' name='clzero'/>
<feature policy='require' name='xsaveerptr'/>
<feature policy='require' name='virt-ssbd'/>
<feature policy='require' name='npt'/>
<feature policy='require' name='nrip-save'/>
<feature policy='require' name='rdctl-no'/>
<feature policy='require' name='skip-l1dfl-vmentry'/>
<feature policy='require' name='mds-no'/>
<feature policy='require' name='pschange-mc-no'/>
<feature policy='disable' name='monitor'/>
<feature policy='require' name='topoext'/>
</cpu>
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
</clock>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/template2204.qcow2' index='2'/>
<backingStore/>
<target dev='vda' bus='virtio'/>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu'/>
<target dev='sda' bus='sata'/>
<readonly/>
<alias name='sata0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0' model='ich9-ehci1'>
<alias name='usb'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x7'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci1'>
<alias name='usb'/>
<master startport='0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci2'>
<alias name='usb'/>
<master startport='2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x1'/>
</controller>
<controller type='usb' index='0' model='ich9-uhci3'>
<alias name='usb'/>
<master startport='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1d' function='0x2'/>
</controller>
<controller type='sata' index='0'>
<alias name='ide'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pcie-root'>
<alias name='pcie.0'/>
</controller>
<controller type='pci' index='1' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='1' port='0x8'/>
<alias name='pci.1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0' multifunction='on'/>
</controller>
<controller type='pci' index='2' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='2' port='0x9'/>
<alias name='pci.2'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='pci' index='3' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='3' port='0xa'/>
<alias name='pci.3'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='4' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='4' port='0xb'/>
<alias name='pci.4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x3'/>
</controller>
<controller type='pci' index='5' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='5' port='0xc'/>
<alias name='pci.5'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x4'/>
</controller>
<controller type='pci' index='6' model='pcie-root-port'>
<model name='pcie-root-port'/>
<target chassis='6' port='0xd'/>
<alias name='pci.6'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x5'/>
</controller>
<controller type='virtio-serial' index='0'>
<alias name='virtio-serial0'/>
<address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
</controller>
<filesystem type='mount' accessmode='mapped'>
<source dir='/var/tomcatlib'/>
<target dir='/libshare'/>
<readonly/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</filesystem>
<filesystem type='mount' accessmode='mapped'>
<source dir='/var/fontlib'/>
<target dir='/fontshare'/>
<readonly/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</filesystem>
<interface type='network'>
<mac address='52:54:00:24:83:d8'/>
<source network='default' portid='7d4a4871-d940-4f25-89b6-b499e6e2eae0' bridge='virbr0'/>
<target dev='vnet0'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
</interface>
<serial type='pty'>
<source path='/dev/pts/1'/>
<target type='isa-serial' port='0'>
<model name='isa-serial'/>
</target>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/1'>
<source path='/dev/pts/1'/>
<target type='serial' port='0'/>
<alias name='serial0'/>
</console>
<channel type='unix'>
<source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-7-template2204/org.qemu.guest_agent.0'/>
<target type='virtio' name='org.qemu.guest_agent.0' state='disconnected'/>
<alias name='channel0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<input type='mouse' bus='ps2'>
<alias name='input0'/>
</input>
<input type='keyboard' bus='ps2'>
<alias name='input1'/>
</input>
<memballoon model='virtio'>
<alias name='balloon0'/>
<address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
</memballoon>
<rng model='virtio'>
<backend model='random'>/dev/urandom</backend>
<alias name='rng0'/>
<address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
</rng>
</devices>
<seclabel type='dynamic' model='dac' relabel='yes'>
<label>+64055:+108</label>
<imagelabel>+64055:+108</imagelabel>
</seclabel>
</domain>

View File

@ -1,17 +0,0 @@
# File soll dynamisch wachsen, preallocation==off
qemu-img create -f qcow2 -o preallocation=off dyn300g.qcow2 300G
mv dyn300g.qcow2 /var/lib/libvirt/images
# Neue VM unter Verwendung dieses files als disk installieren
virt-install \
--name ubuntu2204 \
--ram 4096 \
--disk path=/var/lib/libvirt/images/dyn300g.qcow2 \
--vcpus 2 \
--os-variant ubuntu20.04 \
--network network=default \
--graphics none \
--console pty,target_type=serial \
--location /home/core/tmp/ubuntu-22.04-live-server-amd64.iso,kernel=casper/vmlinuz,initrd=casper/initrd \
--extra-args 'console=ttyS0,115200n8

View File

@ -1,65 +1,6 @@
---
- name: Get VMs list
community.libvirt.virt:
command: list_vms
register: existing_vms
changed_when: no
- name: Create VM if not exists
block:
# - name: Upload base image archiv to core's tmp directory
# copy:
# src: "{{ vm_base_image_archiv }}"
# dest: "/home/core/tmp/"
# owner: libvirt-qemu
# group: kvm
# mode: "0600"
# - name: Gunzip base image in core's tmp directory
# shell:
# cmd: "/usr/bin/gunzip /home/core/tmp/{{ vm_base_image_archiv }}"
# Existierende VM-Disk NICHT überschreiben: force=no. Ergbnis in copy_results speichern: copy_results is changed
- name: Copy unarchived base image to /var/lib/libvirt/images and rename to $vm_name.qcow2 if not exists
copy:
src: "/home/core/tmp/{{ vm_base_image }}"
dest: "{{ libvirt_pool_dir }}/{{ vm_name }}.qcow2"
remote_src: "yes"
owner: libvirt-qemu
group: kvm
mode: "0600"
force: "no"
register: copy_results
- name: Configure the image
command: |
virt-customize -a {{ libvirt_pool_dir }}/{{ vm_name }}.qcow2 \
--hostname {{ vm_name }} \
--root-password password:{{ password }} \
--ssh-inject 'core:file:{{ ssh_key_core }}'
when: copy_results is changed
# Falls das V-File kopiert wurde - weil es das noch nicht gab - wird die VM defined
# Ist eigentlich unnötig, denn der ganze Block wird nicht ausgeführt wenn die VM bereits defined ist
- name: Define vm
community.libvirt.virt:
command: define
xml: "{{ lookup('template', 'template2204.xml') }}"
when: copy_results is changed
when: "vm_name not in existing_vms.list_vms"
- name: Ensure VM is started
community.libvirt.virt:
name: "{{ vm_name }}"
state: running
register: vm_start_results
until: "vm_start_results is success"
retries: 15
delay: 2
- import_tasks: template_upload.yml
- import_tasks: vm_create.yml
- import_tasks: hosts_vm2ip.yml
...

View File

@ -0,0 +1,30 @@
---
# Wir konzentrieren uns auf das gz-File. Falls das nicht existiert wird es hochgeladen.
# Danach wird es entpackt, wenn es nicht bereits existiert. Dabei wird das gz-File nicht
# gelöscht
- name: Check that template file for new vm exists prior to uploading
stat:
path: "/home/core/tmp/{{ vm_base_image_archiv }}"
register: vm_base_image_archiv_exists
- name: Upload base image archiv to core's tmp directory if not exists
copy:
src: "{{ vm_base_image_archiv }}"
dest: "/home/core/tmp/"
owner: core
group: users
mode: "0600"
when: not vm_base_image_archiv_exists.stat.exists
# Falls das entpackte file existiert gibt eine Fehlermeldung wegen "non-zero return code",
# den ignorieren wir
- name: Gunzip base image in core's tmp directory, keep gz file, dont extract if exists
shell:
cmd: "yes n | /usr/bin/gunzip -k /home/core/tmp/{{ vm_base_image_archiv }}"
ignore_errors: true
changed_when: "False"
...

View File

@ -0,0 +1,54 @@
---
- name: Get VMs list
community.libvirt.virt:
command: list_vms
register: existing_vms
changed_when: no
- name: Create VM if not exists
block:
# Existierende VM-Disk NICHT überschreiben: force=no. Ergbnis in copy_results speichern: copy_results is changed
- name: Copy unarchived base image to /var/lib/libvirt/images and rename to $vm_name.qcow2 if not exists
copy:
src: "/home/core/tmp/{{ vm_base_image }}"
dest: "{{ libvirt_pool_dir }}/{{ vm_name }}.qcow2"
remote_src: "yes"
owner: libvirt-qemu
group: kvm
mode: "0600"
force: "no"
register: copy_results
- name: Configure the image
command: |
virt-customize -a {{ libvirt_pool_dir }}/{{ vm_name }}.qcow2 \
--hostname {{ vm_name }} \
--root-password password:{{ password }} \
--ssh-inject 'core:file:{{ ssh_key_core }}'
when: copy_results is changed
# Falls das V-File kopiert wurde - weil es das noch nicht gab - wird die VM defined
# Ist eigentlich unnötig, denn der ganze Block wird nicht ausgeführt wenn die VM bereits defined ist
- name: Define vm
community.libvirt.virt:
command: define
xml: "{{ lookup('template', 'template2204.xml') }}"
when: copy_results is changed
when: "vm_name not in existing_vms.list_vms"
- name: Ensure VM is started
community.libvirt.virt:
name: "{{ vm_name }}"
state: running
register: vm_start_results
until: "vm_start_results is success"
retries: 15
delay: 2
...

View File

@ -4,7 +4,5 @@
become: true
roles:
- kvm_install
#- kvm_installvm
...

10
setupVM.yml Normal file
View File

@ -0,0 +1,10 @@
---
- hosts: "{{ target }}"
remote_user: core
become: true
roles:
#- kvm_install
- kvm_installvm
...