failed_when with multiple conditions not working

Summary

i tested with ” with ‘ without ” without ‘ with ( ) without () and in any other combinations you can imagine

Issue Type

Bug Report

Component Name

general

Ansible Version

$ ansible --version
ansible 2.9.6

Configuration

$ ansible-config dump --only-changed
nothing

OS / Environment

ubuntu 20.04

Steps to Reproduce

- name: "Stop vm if absent"
  proxmox_kvm:
    api_host: "{{ api_host }}"
    api_password: "{{ api_password }}"
    api_user: "{{ api_user }}"
    vmid: "{{ item.value.vmid }}"
    node: "{{ node }}"
    state: "{%% if item.value.state == 'absent' %%}stopped{%% endif %%}"
    force: True
    timeout: 600
  loop: "{{ q('dict', vms) }}"
  when: item.value.state == 'absent'
  register: results

  failed_when:
    - ("VM {{ item.value.vmid }} is already stopped" not in results.msg) or
      ("VM with vmid = {{ item.value.vmid }} does not exist in cluster" not in results.msg)

Expected Results

no changes

Actual Results

error exit on play

Code of Conduct

I agree to follow the Ansible Code of Conduct

1 possible answer(s) on “failed_when with multiple conditions not working

  1. Try:

    failed_when: >-
       results.msg is not contains('VM ' + item.value.vmid + ' is already stopped') or
       results.msg is not contains('VM with id = ' + item.value.vmid + ' does not exist in cluster')