From 4cc4ad48dcc0dac5280abbe8a99a8ea5c44d94d4 Mon Sep 17 00:00:00 2001 From: Jose Date: Sat, 8 Nov 2025 22:43:40 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20Improve=20LXC?= =?UTF-8?q?=20container=20file=20management=20in=20Proxmox=20template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored the Proxmox template to use pct commands for mounting and unmounting the LXC container filesystem, simplifying the process of copying files between containers and the host. This change improves the overall efficiency and reliability of the template. --- tasks/create_proxmox_debian_template.yml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tasks/create_proxmox_debian_template.yml b/tasks/create_proxmox_debian_template.yml index 4cad7ab..52535c7 100644 --- a/tasks/create_proxmox_debian_template.yml +++ b/tasks/create_proxmox_debian_template.yml @@ -20,7 +20,7 @@ lxc_net: "name=eth0,bridge=vmbr0,ip=dhcp" lxc_rootfs_size: "8G" lxc_password: "password" - container_id: "{{ lxc_id }}" + lxc_id: "{{ lxc_id }}" tasks: - block: @@ -234,10 +234,10 @@ # # rsync_opts: # # - "--rsync-path='sudo rsync'" - - name: Copy file from LXC container to Proxmox host using rsync - ansible.builtin.command: > - "rsync -a --rsh=lxc-attach -n {{ lxc_id }} -- {{ workdir }}/{{ template_name }}.qcow2 /var/lib/vz/template/qemu/" - delegate_to: node0 + # - name: Copy file from LXC container to Proxmox host using rsync + # ansible.builtin.command: > + # "rsync -a --rsh=lxc-attach -n {{ lxc_id }} -- {{ workdir }}/{{ template_name }}.qcow2 /var/lib/vz/template/qemu/" + # delegate_to: node0 - name: Import Debian Cloud image as Proxmox VM template @@ -245,6 +245,19 @@ become: true tasks: + + - block: + - name: Mount the LXC container filesystem + command: pct mount "{{ lxc_id }}" + + - name: Copy file from LXC container to the host + copy: + src: "/var/lib/lxc/{{ lxc_id }}/rootfs/{{ workdir }}/{{ template_name }}.qcow2" + dest: "/var/lib/vz/template/qemu/" + + - name: Unmount the LXC container filesystem + command: pct unmount "{{ lxc_id }}" + - block: - name: Import QCOW2 as disk to new VM ansible.builtin.shell: >