diff --git a/tasks/preflight-checks.yml b/tasks/preflight-checks.yml index 58164d4..16e5dfb 100644 --- a/tasks/preflight-checks.yml +++ b/tasks/preflight-checks.yml @@ -168,16 +168,20 @@ set_fact: storage_cfg: "{{ storage_cfg_raw.content | b64decode }}" - - name: "[PREFLIGHT] Add 'snippets' to storage content list if missing" + - name: "[PREFLIGHT] Get current content list of the target storage" + ansible.builtin.shell: > + awk '/^dir: {{ proxmox_snippets_storage }}/,/^$/' /etc/pve/storage.cfg | + awk '/content/ {print $3}' + register: current_content + changed_when: false + + - name: "[PREFLIGHT] Ensure 'snippets' is in the content list" 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) - - storage_cfg is search("storage " + proxmox_snippets_storage + ".*content=") - + 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 != "" + - name: "[PREFLIGHT] Ensure snippets storage exists" ansible.builtin.file: path: "{{ proxmox_snippets_storage_path }}/snippets"