--- - name: Get current VM config via REST API no_log: true # Authorization header carries the API token delegate_to: localhost ansible.builtin.uri: url: "https://{{ pve_vm_api_host }}:8006/api2/json/nodes/{{ pve_vm_node }}/qemu/{{ pve_vm_vmid }}/config" method: GET headers: Authorization: "{{ __pve_vm_api_auth_header }}" register: __pve_vm_current_config # uri has no check mode support; this is a GET, so it also runs under --check and drift # detection sees the live config. check_mode: false - name: Set fact to the actual config dict no_log: true # the config may hold a stored cipassword (update.yml deletes it) ansible.builtin.set_fact: __pve_vm_config: "{{ __pve_vm_current_config.json.data }}" - name: Extract current disk string ansible.builtin.set_fact: __pve_vm_disk_string: "{{ __pve_vm_config[pve_vm_boot_disk] | default('') }}" - name: Extract current disk number and unit properly ansible.builtin.set_fact: __pve_vm_disk_parts: "{{ __pve_vm_disk_string | regex_findall('size=(\\d+)([GM])') | first | default(['0', 'G']) | list }}" - name: Extract current disk number ansible.builtin.set_fact: __pve_vm_current_disk_size_number: "{{ __pve_vm_disk_parts[0] | int }}" __pve_vm_current_disk_size_unit: "{{ __pve_vm_disk_parts[1] }}" - name: Convert disk size to GB ansible.builtin.set_fact: __pve_vm_current_disk: >- {{ __pve_vm_current_disk_size_number if __pve_vm_current_disk_size_unit == 'G' else (__pve_vm_current_disk_size_number / 1024) }} - name: Determine if disk resize is needed ansible.builtin.set_fact: __pve_vm_resize_disk: "{{ pve_vm_disk_size | regex_replace('[^0-9]', '') | int > __pve_vm_current_disk | int }}" when: - pve_vm_manage_disk | bool - pve_vm_disk_size is defined - pve_vm_exists