diff --git a/tasks/preflight-checks.yml b/tasks/preflight-checks.yml index 77cacd9..0fa5d5d 100644 --- a/tasks/preflight-checks.yml +++ b/tasks/preflight-checks.yml @@ -77,17 +77,27 @@ failed_when: false register: vm_id_check -- name: "[PREFLIGHT] Check if VM ID exists in Proxmox cluster" - ansible.builtin.command: "pvesh get /cluster/resources --type vm" +- name: "[PREFLIGHT] Query VM list from cluster" + ansible.builtin.command: > + pvesh get /cluster/resources + --type vm + --output-format json register: cluster_vms changed_when: false + failed_when: false -- name: "[PREFLIGHT] Determine if VM ID is already used" - ansible.builtin.set_fact: - vm_id_exists: "{{ cluster_vms.stdout | from_json | selectattr('vmid', 'equalto', vm_id) | list | length > 0 }}" +- name: "[PREFLIGHT] Determine if VM ID exists" + set_fact: + vm_id_exists: >- + {{ + (cluster_vms.stdout | from_json) + | selectattr('vmid', 'equalto', vm_id) + | list + | length > 0 + }} -- name: "[PREFLIGHT] Fail if VM ID already exists" - ansible.builtin.fail: +- name: "[PREFLIGHT] Fail if VM ID exists" + fail: msg: "VM ID {{ vm_id }} already exists in the Proxmox cluster!" when: vm_id_exists