Files
ansible_proxmox_VM/tasks/download-image.yml
Jose 6361b3fc41 refactor ♻️: Improve retry logic consistency across tasks
Standardized the use of `retries` and `delay` variables in tasks to ensure consistent behavior, making it easier to manage and maintain the workflow. This change also enables better error handling and reduces potential issues with task execution.
2025-11-16 08:02:18 +01:00

42 lines
1.3 KiB
YAML

---
# download-image.yml - Download and cache Debian GenericCloud image
- name: "[IMAGE] Check for Debian GenericCloud image"
ansible.builtin.stat:
path: "{{ debian_image_path }}"
register: debian_img
changed_when: false
- name: "[IMAGE] Create template directory if missing"
ansible.builtin.file:
path: "/var/lib/vz/template/qemu"
state: directory
mode: "0755"
when: not debian_img.stat.exists
- name: "[IMAGE] Download Debian GenericCloud qcow2"
ansible.builtin.get_url:
url: "{{ debian_image_url }}"
dest: "{{ debian_image_path }}"
mode: "0644"
timeout: "{{ image_download_timeout }}"
register: image_download
retries: "{{ max_retries }}"
delay: "{{ retry_delay }}"
until: image_download is succeeded
when: not debian_img.stat.exists
- name: "[IMAGE] Verify downloaded image integrity"
ansible.builtin.stat:
path: "{{ debian_image_path }}"
register: debian_img_final
changed_when: false
failed_when: not debian_img_final.stat.exists or debian_img_final.stat.size == 0
- name: "[IMAGE] Display image info"
ansible.builtin.debug:
msg: |
Image cached at: {{ debian_image_path }}
Size: {{ debian_img_final.stat.size | int / 1024 / 1024 / 1024 | round(2) }} GB
Last modified: {{ debian_img_final.stat.mtime | timestamp_to_datetime }}