Skip to content

Perf Optimization idea - Store downloaded ISOs in Proxmox Iso storage

When creating role currently you are using defaults/main.yml:

ludus_install_directory: /opt/ludus
ludus_X_iso_directory: "C:\\ludus"
ludus_X_iso_url: "https://download.com/download/X.ISO"

Then you are downloading ISO from URL in tasks/main.yml :

- name: Get X ISO if needed
  run_once: true
  block:
    - name: Create /opt/ludus/resources/iso directory if it doesn't exist
      ansible.builtin.file:
        path: "{{ ludus_install_directory }}/resources/iso"
        state: directory
        recurse: true
      delegate_to: localhost

    - name: Check if X ISO exists
      ansible.builtin.stat:
        path: "{{ ludus_install_directory }}/resources/iso/{{ ludus_x_iso_url.split('/') | last }}"
      delegate_to: localhost
      register: x_iso_check

    - name: Downloading X ISO - This will take a while
      ansible.builtin.get_url:
        url: "{{ ludus_x_iso_url }}"
        dest: "{{ ludus_install_directory }}/resources/iso/{{ ludus_x_iso_url.split('/') | last }}"
        mode: "660"
      delegate_to: localhost
      when: not x_iso_check.stat.exists

- name: Check if X ISO exists on host
  ansible.windows.win_stat:
    path: "{{ ludus_x_iso_directory }}\\{{ ludus_x_iso_url.split('/') | last }}"
  register: x_iso_host_check

- name: Copy X ISO to windows host
  ansible.windows.win_copy:
    src: "{{ ludus_install_directory }}/resources/iso/{{ ludus_x_iso_url.split('/') | last }}"
    dest: "{{ ludus_x_iso_directory }}\\{{ ludus_x_iso_url.split('/') | last }}"
  when: not x_iso_host_check.stat.exists

And you are uploading the ISO to the VM to mount it in tasks/main.yml

- name: Mount X ISO
  community.windows.win_disk_image:
    image_path: "{{ ludus_X_iso_directory }}\\{{ ludus_X_iso_url.split('/') | last }}"
    state: present
  register: iso_mount

Ludus ISOs are located in : /opt/ludus/resources/iso/

If ISO makes 5Go the for each install :

  • 5 Go is written in the VM disk
  • it takes about 10 minutes to upload to the VM
  • it will take time to delete the ISO from VM disk
  • the space used will stay used in the disk image (qcow size)

SOLUTION that could work :

ludus_install_directory: /opt/ludus
ludus_X_iso_directory: "C:\\ludus"
ludus_X_iso_url: "https://download.com/download/X.ISO"

Then you are downloading ISO from URL in tasks/main.yml but changing the destination to the storage of the Proxmox ISOs that are located in : /var/lib/vz/template/iso/

Then you can just mount the ISO with the command : qm set 124 --cdrom "local:iso/SERVER_EVAL_x64FRE_en-us.iso"

It could give a configuration like that :

- name: Get X ISO if needed
  run_once: true
  block:
    - name: Check if X ISO exists
      ansible.builtin.stat:
        path: "/var/lib/vz/template/iso/{{ ludus_x_iso_url.split('/') | last }}"
      delegate_to: localhost
      register: x_iso_check

    - name: Downloading X ISO - This will take a while
      ansible.builtin.get_url:
        url: "{{ ludus_x_iso_url }}"
        dest: "/var/lib/vz/template/iso/{{ ludus_x_iso_url.split('/') | last }}"
        mode: "660"
      delegate_to: localhost
      when: not x_iso_check.stat.exists

- name: Mount X ISO
  ansible.builtin.shell: qm set {{ proxmox_vmid }} --cdrom "{{ proxmox_vm_storage_pool }}:iso/{{ ludus_X_iso_url.split('/') | last }}"
  register: iso_mount
  delegate_to: localhost

And later after installation :

- name: Unmount X ISO
  ansible.builtin.shell: qm set {{ proxmox_vmid }} --cdrom none
  register: iso_mount_unmount
  delegate_to: localhost

There is a workaround to find about user rights