diff --git a/tasks/asserts.yml b/tasks/asserts.yml index f724043..b7689d8 100644 --- a/tasks/asserts.yml +++ b/tasks/asserts.yml @@ -41,11 +41,11 @@ - _disk.disk is defined - _disk.disk | length > 0 - _disk.size is defined - - _disk.size is match('^[0-9]+[KMGT]$') + - _disk.size | string is match('^[0-9]+[GT]?$') fail_msg: >- Disque supplémentaire invalide : {{ _disk }}. - 'disk' (ex: scsi1) et 'size' (ex: 100G) sont obligatoires. - La taille doit être absolue (pas de préfixe +). + 'disk' (ex: scsi1) et 'size' (ex: '100G' ou 100) sont obligatoires. + Formats acceptés : entier en GB (ex: 20) ou chaîne avec unité G/T (ex: '20G', '2T'). loop: "{{ vm_extra_disks }}" loop_control: loop_var: _disk diff --git a/tasks/configure.yml b/tasks/configure.yml index 6d781be..64bd3f0 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -64,7 +64,14 @@ - name: "deploy-vm | add extra disk '{{ _disk.disk }}' ({{ _disk.size }})" vars: - _opts: "{{ _disk.storage | default(proxmox_storage) }}:0,size={{ _disk.size\ + # Proxmox API format : storage:SIZE_GB[,options] + # SIZE_GB doit être un entier en GB (sans unité). + # Formats acceptés : entier brut (20 → 20 GB), chaîne avec unité G ("20G") ou T ("2T"). + _size_gb: >- + {{ (_disk.size | string)[:-1] | int * 1024 if (_disk.size | string)[-1] | upper == 'T' + else (_disk.size | string)[:-1] | int if (_disk.size | string)[-1] | upper == 'G' + else _disk.size | int }} + _opts: "{{ _disk.storage | default(proxmox_storage) }}:{{ _size_gb\ }}{{ ',ssd=1' if _disk.ssd | default(false) | bool else ''\ }}{{ ',iothread=1' if _disk.iothread | default(false) | bool else ''\ }}{{ ',backup=0' if not (_disk.backup | default(true) | bool) else ''\