fix: streamline validation for Proxmox storage snippets support
This commit is contained in:
@@ -159,28 +159,15 @@
|
|||||||
|
|
||||||
- name: "[PREFLIGHT] Ensure Proxmox storage supports snippets"
|
- name: "[PREFLIGHT] Ensure Proxmox storage supports snippets"
|
||||||
block:
|
block:
|
||||||
- name: "[PREFLIGHT] Read storage.cfg"
|
- name: "[PREFLIGHT] Ensure 'snippets' is in the content list for dir storage"
|
||||||
ansible.builtin.slurp:
|
ansible.builtin.lineinfile:
|
||||||
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:
|
|
||||||
path: /etc/pve/storage.cfg
|
path: /etc/pve/storage.cfg
|
||||||
regexp: "(?m)(^dir: {{ proxmox_snippets_storage }}[\\s\\S]*?content\\s*=\\s*)([^\\n]+)"
|
regexp: "^(\\s*content\\s+)(.*)$"
|
||||||
replace: "\\1{{ (current_content.stdout.split(',') | union(['snippets'])) | join(',') }}"
|
line: '\1{{ (ansible_facts.storage_content.split(",") | union(["snippets"])) | join(",") }}'
|
||||||
when: current_content.stdout != ""
|
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"
|
- name: "[PREFLIGHT] Ensure snippets storage exists"
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
|
|||||||
Reference in New Issue
Block a user