Files
ansible_proxmox_VM/tasks/download-image.yml

44 lines
1.4 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
{{ debian_img_final.stat.mtime }}
{{ debian_img_final.stat.mtime | type_debug }}
# Last modified: {{ debian_img_final.stat.mtime | int | strftime('%Y-%m-%d %H:%M:%S') }}