From e42875a45df1859d38d95a6a712667a859f205a0 Mon Sep 17 00:00:00 2001 From: Jose Date: Sat, 8 Nov 2025 09:38:28 +0100 Subject: [PATCH] =?UTF-8?q?style=20=F0=9F=92=8E:=20Update=20image=20compre?= =?UTF-8?q?ssion=20and=20shrinking=20steps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated the Ansible playbook to use virt-sparsify for compressing and shrinking images, replacing a previous qemu-img command. This change improves efficiency and reduces storage requirements. --- tasks/create_proxmox_debian_template.yml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tasks/create_proxmox_debian_template.yml b/tasks/create_proxmox_debian_template.yml index 9cd329e..1fc36ce 100644 --- a/tasks/create_proxmox_debian_template.yml +++ b/tasks/create_proxmox_debian_template.yml @@ -10,7 +10,8 @@ vars: lxc_name: "debian-builder" lxc_id: 9900 - lxc_storage: "local-lvm" + # lxc_storage: "local-lvm" + lxc_storage: "hdd8t" lxc_template: "local:vztmpl/debian-13-standard_13.1-1_amd64.tar.zst" lxc_ostype: "debian" lxc_cores: 2 @@ -140,10 +141,26 @@ virt-customize -a {{ workdir }}/{{ image_name }} \ --run-command 'truncate -s 0 /etc/machine-id && rm -f /var/lib/dbus/machine-id' - - name: Compress and shrink image + - name: Convert image to compressed qcow2 ansible.builtin.shell: | qemu-img convert -O qcow2 -c {{ workdir }}/{{ image_name }} {{ workdir }}/{{ template_name }}.qcow2 - qemu-img resize {{ workdir }}/{{ template_name }}.qcow2 --shrink + args: + creates: "{{ workdir }}/{{ template_name }}.qcow2" + + - name: Shrink the compressed qcow2 using virt-sparsify + ansible.builtin.shell: | + virt-sparsify --compress {{ workdir }}/{{ template_name }}.qcow2 {{ workdir }}/{{ template_name }}_sparse.qcow2 + args: + creates: "{{ workdir }}/{{ template_name }}_sparse.qcow2" + + - name: Replace original compressed image with sparsified version + ansible.builtin.shell: | + mv {{ workdir }}/{{ template_name }}_sparse.qcow2 {{ workdir }}/{{ template_name }}.qcow2 + + # - name: Compress and shrink image + # ansible.builtin.shell: | + # qemu-img convert -O qcow2 -c {{ workdir }}/{{ image_name }} {{ workdir }}/{{ template_name }}.qcow2 + # qemu-img resize {{ workdir }}/{{ template_name }}.qcow2 --shrink - name: Copy finished template back to Proxmox host ansible.builtin.synchronize: