--- # no_log hides the whole failure of the lookup below, so the operator would only see "output hidden # due to no_log". The rescue re-raises just the module's msg, which is safe to show: the module # masks the token secret in everything it returns (its invocation echo is not used here). - name: Look up the VM block: - name: Check if VM exists no_log: true # defence in depth: the module already masks the API token secret delegate_to: "{{ pve_vm_delegate }}" community.proxmox.proxmox_kvm: node: "{{ pve_vm_node }}" vmid: "{{ pve_vm_vmid }}" state: current register: __pve_vm_info # proxmox_kvm declares no check mode support, so --check would skip this lookup, leave # pve_vm_exists false and skip everything after it. state=current only reads (GET of the VM # and its status), so it runs for real under --check as well. check_mode: false # An absent VM is an expected answer here: for state=current the module fails with # "VM with vmid does not exist in cluster". Any other failure (API, auth, network) is # real and must stop the run instead of being read as "VM absent", which would send # create.yml after an existing VM. failed_when: - __pve_vm_info.failed | default(false) - "'does not exist in cluster' not in (__pve_vm_info.msg | default(''))" changed_when: false rescue: - name: Fail with the module message ansible.builtin.fail: msg: >- Looking up VM {{ pve_vm_vmid }} on {{ pve_vm_node }} failed: {{ ansible_failed_result.msg | default('no message') }} - name: Set VM existence fact ansible.builtin.set_fact: pve_vm_exists: >- {{ __pve_vm_info.vmid is defined or __pve_vm_info.status is defined }}