fix: streamline validation for Proxmox storage snippets support

This commit is contained in:
2025-12-06 08:55:51 +01:00
parent 1a0af3b6e6
commit 9495475e58

View File

@@ -159,28 +159,15 @@
- 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] Get current content list of the target storage"
ansible.builtin.shell: >
awk '/^dir: {{ proxmox_snippets_storage }}/,/^$/' /etc/pve/storage.cfg |
awk '/content/ {sub(/^content[[:space:]]*/, ""); print}'
register: current_content
changed_when: false
- name: "[PREFLIGHT] Ensure 'snippets' is in the content list"
ansible.builtin.replace:
- name: "[PREFLIGHT] Ensure 'snippets' is in the content list for dir storage"
ansible.builtin.lineinfile:
path: /etc/pve/storage.cfg
regexp: "(?m)(^dir: {{ proxmox_snippets_storage }}[\\s\\S]*?content\\s*=\\s*)([^\\n]+)"
replace: "\\1{{ (current_content.stdout.split(',') | union(['snippets'])) | join(',') }}"
when: current_content.stdout != ""
regexp: "^(\\s*content\\s+)(.*)$"
line: '\1{{ (ansible_facts.storage_content.split(",") | union(["snippets"])) | join(",") }}'
backrefs: yes
vars:
ansible_facts:
storage_content: "{{ lookup('ansible.builtin.lines', '/etc/pve/storage.cfg') | select('match', '^\\s*dir: {{ proxmox_snippets_storage }}') | list | map('regex_search', '^\\s*content\\s+(.*)$') | select('string') | first | default('') }}"
- name: "[PREFLIGHT] Ensure snippets storage exists"
ansible.builtin.file: