fix: add support for Proxmox snippets storage configuration and update related paths

This commit is contained in:
2025-12-06 08:08:26 +01:00
parent 6d7fc713a2
commit 15325213ab
5 changed files with 49 additions and 23 deletions

View File

@@ -32,6 +32,10 @@ bridge: vmbr0
# Proxmox storage pool for VM disks
storage: local-lvm
# Proxmox storage pool for snippets
proxmox_snippets_storage: local
proxmox_snippets_storage_path: /var/lib/vz
###############################################################################
# MAC ADDRESS GENERATION (avoids collisions)
###############################################################################
@@ -52,8 +56,8 @@ mac_address: "{{ mac_base }}:{{ mac_suffix }}"
debian_image_url: "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.qcow2"
# Local path where image is cached
# debian_image_path: "/var/lib/vz/template/qemu/debian-genericcloud-amd64.qcow2"
debian_image_path: "/var/lib/vz/template/qemu/debian-13-genericcloud-amd64.qcow2"
# debian_image_path: "{{ proxmox_snippets_storage_path }}/template/qemu/debian-genericcloud-amd64.qcow2"
debian_image_path: "{{ proxmox_snippets_storage_path }}/template/qemu/debian-13-genericcloud-amd64.qcow2"
###############################################################################
# NETWORKING CONFIGURATION

View File

@@ -126,7 +126,7 @@
- name: "[CONFIG] Create Cloud-Init vendor-data snippet"
ansible.builtin.template:
src: cloudinit_vendor.yaml.j2
dest: "/var/lib/vz/snippets/{{ vm_id }}-vendor.yaml"
dest: "{{ proxmox_snippets_storage_path }}/snippets/{{ vm_id }}-vendor.yaml"
mode: "0644"
register: vendor_snippet
@@ -139,14 +139,14 @@
- name: "[CONFIG] Create Cloud-Init user-data snippet"
ansible.builtin.template:
src: cloudinit_userdata.yaml.j2
dest: "/var/lib/vz/snippets/{{ vm_id }}-user.yaml"
dest: "{{ proxmox_snippets_storage_path }}/snippets/{{ vm_id }}-user.yaml"
mode: "0644"
register: user_snippet
- name: "[CONFIG] Copy SSH public key to snippets"
ansible.builtin.copy:
src: "{{ ssh_keys_file }}"
dest: "/var/lib/vz/snippets/{{ vm_id }}-sshkey.pub"
dest: "{{ proxmox_snippets_storage_path }}/snippets/{{ vm_id }}-sshkey.pub"
remote_src: true
mode: "0644"
register: ssh_snippet

View File

@@ -9,7 +9,7 @@
- name: "[IMAGE] Create template directory if missing"
ansible.builtin.file:
path: "/var/lib/vz/template/qemu"
path: "{{ proxmox_snippets_storage_path }}/template/qemu"
state: directory
mode: "0755"
when: not debian_img.stat.exists

View File

@@ -142,9 +142,9 @@
path: "{{ item }}"
state: absent
loop:
- "/var/lib/vz/snippets/{{ target_vm_id }}-user.yaml"
- "/var/lib/vz/snippets/{{ target_vm_id }}-vendor.yaml"
- "/var/lib/vz/snippets/{{ target_vm_id }}-sshkey.pub"
- "{{ proxmox_snippets_storage_path }}/snippets/{{ target_vm_id }}-user.yaml"
- "{{ proxmox_snippets_storage_path }}/snippets/{{ target_vm_id }}-vendor.yaml"
- "{{ proxmox_snippets_storage_path }}/snippets/{{ target_vm_id }}-sshkey.pub"
when: helper_task == "cleanup_snippets"

View File

@@ -79,7 +79,6 @@
failed_when: not ssh_key_file.stat.exists
changed_when: false
- name: "[PREFLIGHT] Validate VM ID is unique"
ansible.builtin.command: "test ! -f /etc/pve/qemu-server/{{ vm_id }}.conf"
changed_when: false
@@ -158,24 +157,47 @@
loop: "{{ dns }}"
when: dns is defined and dns | length > 0
- name: "[PREFLIGHT] Ensure snippets storage exists"
ansible.builtin.file:
path: "/var/lib/vz/snippets"
state: directory
mode: "0755"
- name: "[PREFLIGHT] Check snippets storage exists"
ansible.builtin.stat:
path: "/var/lib/vz/snippets"
register: snippets_dir
failed_when: not snippets_dir.stat.exists
changed_when: false
- name: "[PREFLIGHT] Ensure Proxmox storage supports snippets"
block:
- name: "[PREFLIGHT] Read storage.cfg"
ansible.builtin.slurp:
src: /etc/pve/storage.cfg
register: storage_cfg_raw
- name: "[PREFLIGHT] Decode storage.cfg"
set_fact:
storage_cfg: "{{ storage_cfg_raw.content | b64decode }}"
- name: "[PREFLIGHT] Add 'snippets' to storage content list if missing"
ansible.builtin.replace:
path: /etc/pve/storage.cfg
regexp: "(?m)(^storage {{ proxmox_snippets_storage }}.*?content\\s*=\\s*)([^\n]+)"
replace: >-
\1{{ ( '\2'.split(',') | union(['snippets']) ) | join(',') }}
when: storage_cfg is search("storage {{ proxmox_snippets_storage }}") and
storage_cfg is search("storage {{ proxmox_snippets_storage }}.*content=")
- name: "[PREFLIGHT] Ensure snippets storage exists"
ansible.builtin.file:
path: "{{ proxmox_snippets_storage_path }}/snippets"
state: directory
mode: "0755"
- name: "[PREFLIGHT] Check snippets storage exists"
ansible.builtin.stat:
path: "{{ proxmox_snippets_storage_path }}/snippets"
register: snippets_dir
failed_when: not snippets_dir.stat.exists
changed_when: false
become: true
- name: "[PREFLIGHT] Summary - All checks passed"
ansible.builtin.debug:
msg: |
✓ Proxmox environment validated
✓ Storage pool '{{ storage }}' available
✓ Storage pool '{{ storage }}' available for VM disks
✓ Storage pool '{{ proxmox_snippets_storage }}' available for snippets
✓ SSH key found at {{ ssh_key_path }}
✓ VM ID {{ vm_id }} is available
✓ Ready to create VM: {{ hostname }}