fix: add support for Proxmox snippets storage configuration and update related paths
This commit is contained in:
@@ -32,6 +32,10 @@ bridge: vmbr0
|
|||||||
# Proxmox storage pool for VM disks
|
# Proxmox storage pool for VM disks
|
||||||
storage: local-lvm
|
storage: local-lvm
|
||||||
|
|
||||||
|
# Proxmox storage pool for snippets
|
||||||
|
proxmox_snippets_storage: local
|
||||||
|
proxmox_snippets_storage_path: /var/lib/vz
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# MAC ADDRESS GENERATION (avoids collisions)
|
# 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"
|
debian_image_url: "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.qcow2"
|
||||||
|
|
||||||
# Local path where image is cached
|
# Local path where image is cached
|
||||||
# debian_image_path: "/var/lib/vz/template/qemu/debian-genericcloud-amd64.qcow2"
|
# debian_image_path: "{{ proxmox_snippets_storage_path }}/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-13-genericcloud-amd64.qcow2"
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# NETWORKING CONFIGURATION
|
# NETWORKING CONFIGURATION
|
||||||
|
|||||||
@@ -126,7 +126,7 @@
|
|||||||
- name: "[CONFIG] Create Cloud-Init vendor-data snippet"
|
- name: "[CONFIG] Create Cloud-Init vendor-data snippet"
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: cloudinit_vendor.yaml.j2
|
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"
|
mode: "0644"
|
||||||
register: vendor_snippet
|
register: vendor_snippet
|
||||||
|
|
||||||
@@ -139,14 +139,14 @@
|
|||||||
- name: "[CONFIG] Create Cloud-Init user-data snippet"
|
- name: "[CONFIG] Create Cloud-Init user-data snippet"
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: cloudinit_userdata.yaml.j2
|
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"
|
mode: "0644"
|
||||||
register: user_snippet
|
register: user_snippet
|
||||||
|
|
||||||
- name: "[CONFIG] Copy SSH public key to snippets"
|
- name: "[CONFIG] Copy SSH public key to snippets"
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: "{{ ssh_keys_file }}"
|
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
|
remote_src: true
|
||||||
mode: "0644"
|
mode: "0644"
|
||||||
register: ssh_snippet
|
register: ssh_snippet
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
- name: "[IMAGE] Create template directory if missing"
|
- name: "[IMAGE] Create template directory if missing"
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "/var/lib/vz/template/qemu"
|
path: "{{ proxmox_snippets_storage_path }}/template/qemu"
|
||||||
state: directory
|
state: directory
|
||||||
mode: "0755"
|
mode: "0755"
|
||||||
when: not debian_img.stat.exists
|
when: not debian_img.stat.exists
|
||||||
|
|||||||
@@ -142,9 +142,9 @@
|
|||||||
path: "{{ item }}"
|
path: "{{ item }}"
|
||||||
state: absent
|
state: absent
|
||||||
loop:
|
loop:
|
||||||
- "/var/lib/vz/snippets/{{ target_vm_id }}-user.yaml"
|
- "{{ proxmox_snippets_storage_path }}/snippets/{{ target_vm_id }}-user.yaml"
|
||||||
- "/var/lib/vz/snippets/{{ target_vm_id }}-vendor.yaml"
|
- "{{ proxmox_snippets_storage_path }}/snippets/{{ target_vm_id }}-vendor.yaml"
|
||||||
- "/var/lib/vz/snippets/{{ target_vm_id }}-sshkey.pub"
|
- "{{ proxmox_snippets_storage_path }}/snippets/{{ target_vm_id }}-sshkey.pub"
|
||||||
|
|
||||||
when: helper_task == "cleanup_snippets"
|
when: helper_task == "cleanup_snippets"
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,6 @@
|
|||||||
failed_when: not ssh_key_file.stat.exists
|
failed_when: not ssh_key_file.stat.exists
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
|
||||||
|
|
||||||
- name: "[PREFLIGHT] Validate VM ID is unique"
|
- name: "[PREFLIGHT] Validate VM ID is unique"
|
||||||
ansible.builtin.command: "test ! -f /etc/pve/qemu-server/{{ vm_id }}.conf"
|
ansible.builtin.command: "test ! -f /etc/pve/qemu-server/{{ vm_id }}.conf"
|
||||||
changed_when: false
|
changed_when: false
|
||||||
@@ -158,24 +157,47 @@
|
|||||||
loop: "{{ dns }}"
|
loop: "{{ dns }}"
|
||||||
when: dns is defined and dns | length > 0
|
when: dns is defined and dns | length > 0
|
||||||
|
|
||||||
- name: "[PREFLIGHT] Ensure snippets storage exists"
|
- name: "[PREFLIGHT] Ensure Proxmox storage supports snippets"
|
||||||
ansible.builtin.file:
|
block:
|
||||||
path: "/var/lib/vz/snippets"
|
- name: "[PREFLIGHT] Read storage.cfg"
|
||||||
state: directory
|
ansible.builtin.slurp:
|
||||||
mode: "0755"
|
src: /etc/pve/storage.cfg
|
||||||
|
register: storage_cfg_raw
|
||||||
- name: "[PREFLIGHT] Check snippets storage exists"
|
|
||||||
ansible.builtin.stat:
|
- name: "[PREFLIGHT] Decode storage.cfg"
|
||||||
path: "/var/lib/vz/snippets"
|
set_fact:
|
||||||
register: snippets_dir
|
storage_cfg: "{{ storage_cfg_raw.content | b64decode }}"
|
||||||
failed_when: not snippets_dir.stat.exists
|
|
||||||
changed_when: false
|
- 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"
|
- name: "[PREFLIGHT] Summary - All checks passed"
|
||||||
ansible.builtin.debug:
|
ansible.builtin.debug:
|
||||||
msg: |
|
msg: |
|
||||||
✓ Proxmox environment validated
|
✓ 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 }}
|
✓ SSH key found at {{ ssh_key_path }}
|
||||||
✓ VM ID {{ vm_id }} is available
|
✓ VM ID {{ vm_id }} is available
|
||||||
✓ Ready to create VM: {{ hostname }}
|
✓ Ready to create VM: {{ hostname }}
|
||||||
|
|||||||
Reference in New Issue
Block a user