diff --git a/default.xml b/default.xml
deleted file mode 100644
index e1ed832..0000000
--- a/default.xml
+++ /dev/null
@@ -1,114 +0,0 @@
-
- vhostxpm
- 15666f6a-c48b-49b1-a2f9-2b01193cb204
- XIT Projektmanagement
- 6291456
- 4194304
- 4
-
- hvm
-
-
-
-
-
-
-
-
- Broadwell-noTSX-IBRS
-
-
-
-
-
-
- destroy
- restart
- destroy
-
-
-
-
-
- /usr/bin/kvm-spice
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/host_vars/bbb.xitq.de b/host_vars/bbb.xitq.de
index 95d1f59..40bdc31 100644
--- a/host_vars/bbb.xitq.de
+++ b/host_vars/bbb.xitq.de
@@ -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
diff --git a/installimageBuffer b/roles/install_image/files/installimageBuffer
similarity index 100%
rename from installimageBuffer
rename to roles/install_image/files/installimageBuffer
diff --git a/roles/kvm_install/tasks/main.yml b/roles/kvm_install/tasks/main.yml
index 3e145fe..c076a2c 100644
--- a/roles/kvm_install/tasks/main.yml
+++ b/roles/kvm_install/tasks/main.yml
@@ -1,8 +1,5 @@
---
- import_tasks: packages_install.yml
- import_tasks: script_upload.yml
-- import_tasks: hosts_vm2ip.yml
-
-
...
\ No newline at end of file
diff --git a/roles/kvm_installvm/files/dyn300g.qcow2 b/roles/kvm_installvm/files/dyn300g.qcow2
deleted file mode 100644
index 2b667ee..0000000
Binary files a/roles/kvm_installvm/files/dyn300g.qcow2 and /dev/null differ
diff --git a/roles/kvm_installvm/files/template2204.qcow2.gz b/roles/kvm_installvm/files/template2204.qcow2.gz
deleted file mode 100644
index 6dcfa4d..0000000
Binary files a/roles/kvm_installvm/files/template2204.qcow2.gz and /dev/null differ
diff --git a/roles/kvm_installvm/files/template2204.xml b/roles/kvm_installvm/files/template2204.xml
deleted file mode 100644
index 8fe7151..0000000
--- a/roles/kvm_installvm/files/template2204.xml
+++ /dev/null
@@ -1,200 +0,0 @@
-
- template2204
- b23e5e10-6e7b-4199-968d-8ee7c23ed636
-
-
-
-
-
- 4194304
- 4194304
- 2
-
- /machine
-
-
- hvm
-
-
-
-
-
-
-
- EPYC-IBPB
- AMD
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- destroy
- restart
- destroy
-
-
-
-
-
- /usr/bin/qemu-system-x86_64
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /dev/urandom
-
-
-
-
-
-
- +64055:+108
-
-
-
diff --git a/roles/kvm_installvm/files/virt-install_ubuntu_2204.sh b/roles/kvm_installvm/files/virt-install_ubuntu_2204.sh
deleted file mode 100644
index 5fdc4fa..0000000
--- a/roles/kvm_installvm/files/virt-install_ubuntu_2204.sh
+++ /dev/null
@@ -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
diff --git a/roles/kvm_install/tasks/hosts_vm2ip.yml b/roles/kvm_installvm/tasks/hosts_vm2ip.yml
similarity index 100%
rename from roles/kvm_install/tasks/hosts_vm2ip.yml
rename to roles/kvm_installvm/tasks/hosts_vm2ip.yml
diff --git a/roles/kvm_installvm/tasks/main.yml b/roles/kvm_installvm/tasks/main.yml
index 1aad7fd..47b7407 100644
--- a/roles/kvm_installvm/tasks/main.yml
+++ b/roles/kvm_installvm/tasks/main.yml
@@ -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
...
\ No newline at end of file
diff --git a/roles/kvm_installvm/tasks/template_upload.yml b/roles/kvm_installvm/tasks/template_upload.yml
new file mode 100644
index 0000000..8559273
--- /dev/null
+++ b/roles/kvm_installvm/tasks/template_upload.yml
@@ -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"
+
+
+...
\ No newline at end of file
diff --git a/roles/kvm_installvm/tasks/vm_create.yml b/roles/kvm_installvm/tasks/vm_create.yml
new file mode 100644
index 0000000..5691dfb
--- /dev/null
+++ b/roles/kvm_installvm/tasks/vm_create.yml
@@ -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
+
+
+...
\ No newline at end of file
diff --git a/ubuntu2204.xml b/roles/kvm_installvmXML/files/ubuntu2204.xml
similarity index 100%
rename from ubuntu2204.xml
rename to roles/kvm_installvmXML/files/ubuntu2204.xml
diff --git a/roles/kvm_installvm/tasks/main.backup.yml b/roles/kvm_installvmXML/tasks/main.yml
similarity index 100%
rename from roles/kvm_installvm/tasks/main.backup.yml
rename to roles/kvm_installvmXML/tasks/main.yml
diff --git a/setupKVMwirt.yml b/setupKVMwirt.yml
index 3051325..fb26143 100644
--- a/setupKVMwirt.yml
+++ b/setupKVMwirt.yml
@@ -4,7 +4,5 @@
become: true
roles:
- kvm_install
- #- kvm_installvm
-
...
\ No newline at end of file
diff --git a/setupVM.yml b/setupVM.yml
new file mode 100644
index 0000000..ccc3e21
--- /dev/null
+++ b/setupVM.yml
@@ -0,0 +1,10 @@
+---
+- hosts: "{{ target }}"
+ remote_user: core
+ become: true
+ roles:
+ #- kvm_install
+ - kvm_installvm
+
+
+...
\ No newline at end of file