refactor ♻️: Improve LXC container file management in Proxmox template
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.
This commit is contained in:
@@ -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: >
|
||||
|
||||
Reference in New Issue
Block a user