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
|
state: present
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
|
||||||
|
- name: "[PREFLIGHT] Check if 'snippets' is already enabled for {{ proxmox_snippets_storage }}"
|
||||||
# - name: "[PREFLIGHT] Ensure 'snippets' is enabled for {{ proxmox_snippets_storage }}"
|
ansible.builtin.command: "grep -E 'dir:\\s*{{ proxmox_snippets_storage }}' -A5 /etc/pve/storage.cfg"
|
||||||
# ansible.builtin.replace:
|
register: snippets_check
|
||||||
# path: /etc/pve/storage.cfg
|
failed_when: false
|
||||||
# regexp: '(dir:\s*{{ proxmox_snippets_storage }}[\s\S]*?content\s+)(.*)(?<!snippets)'
|
changed_when: false
|
||||||
# replace: '\1\2,snippets'
|
vars:
|
||||||
# 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:
|
|
||||||
proxmox_snippets_storage: local
|
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"
|
- name: "[PREFLIGHT] Ensure snippets storage directory exists"
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
|
|||||||
Reference in New Issue
Block a user