refactor ♻️: Preflight: Snippets configuration check
This commit refactors the preflight task to intelligently check if the 'snippets' configuration is already present in the `/etc/pve/storage.cfg` file. It avoids redundant replacement operations and improves the preflight process by determining if the configuration is already set, preventing unnecessary modifications.
This commit is contained in:
@@ -10,23 +10,24 @@
|
||||
state: present
|
||||
update_cache: yes
|
||||
|
||||
|
||||
# - name: "[PREFLIGHT] Ensure 'snippets' is enabled for {{ proxmox_snippets_storage }}"
|
||||
# ansible.builtin.replace:
|
||||
# path: /etc/pve/storage.cfg
|
||||
# regexp: '(dir:\s*{{ proxmox_snippets_storage }}[\s\S]*?content\s+)(.*)(?<!snippets)'
|
||||
# replace: '\1\2,snippets'
|
||||
# vars:
|
||||
# proxmox_snippets_storage: local
|
||||
|
||||
- name: "Ensure 'snippets' is enabled for {{ proxmox_snippets_storage }}"
|
||||
ansible.builtin.replace:
|
||||
path: /etc/pve/storage.cfg
|
||||
regexp: '(?ms)(dir:\s*{{ proxmox_snippets_storage }}\b.*?content\s*=\s*(?!.*snippets)([^ \n]+))'
|
||||
replace: '\1,snippets'
|
||||
vars:
|
||||
- name: "[PREFLIGHT] Check if 'snippets' is already enabled for {{ proxmox_snippets_storage }}"
|
||||
ansible.builtin.command: "grep -E 'dir:\\s*{{ proxmox_snippets_storage }}' -A5 /etc/pve/storage.cfg"
|
||||
register: snippets_check
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
vars:
|
||||
proxmox_snippets_storage: local
|
||||
|
||||
- name: "[PREFLIGHT] Determine whether 'snippets' is already configured"
|
||||
ansible.builtin.set_fact:
|
||||
snippets_already_present: "{{ 'snippets' in snippets_check.stdout }}"
|
||||
|
||||
- name: "[PREFLIGHT] Ensure 'snippets' is enabled for {{ proxmox_snippets_storage }}"
|
||||
ansible.builtin.replace:
|
||||
path: /etc/pve/storage.cfg
|
||||
regexp: '(dir:\s*{{ proxmox_snippets_storage }}[\s\S]*?content\s+)(.*)(?<!snippets)'
|
||||
replace: '\1\2,snippets'
|
||||
when: not snippets_already_present
|
||||
|
||||
- name: "[PREFLIGHT] Ensure snippets storage directory exists"
|
||||
ansible.builtin.file:
|
||||
|
||||
Reference in New Issue
Block a user